src/share/classes/com/sun/tools/javac/code/Types.java

changeset 1653
f3814edefb33
parent 1644
40adaf938847
child 1655
c6728c9addff
     1.1 --- a/src/share/classes/com/sun/tools/javac/code/Types.java	Fri Mar 22 12:38:12 2013 +0000
     1.2 +++ b/src/share/classes/com/sun/tools/javac/code/Types.java	Fri Mar 22 12:39:34 2013 +0000
     1.3 @@ -1418,23 +1418,10 @@
     1.4                      }
     1.5                  }
     1.6  
     1.7 -                if (t.isCompound()) {
     1.8 -                    Warner oldWarner = warnStack.head;
     1.9 -                    warnStack.head = noWarnings;
    1.10 -                    if (!visit(supertype(t), s))
    1.11 -                        return false;
    1.12 -                    for (Type intf : interfaces(t)) {
    1.13 -                        if (!visit(intf, s))
    1.14 -                            return false;
    1.15 -                    }
    1.16 -                    if (warnStack.head.hasLint(LintCategory.UNCHECKED))
    1.17 -                        oldWarner.warn(LintCategory.UNCHECKED);
    1.18 -                    return true;
    1.19 -                }
    1.20 -
    1.21 -                if (s.isCompound()) {
    1.22 -                    // call recursively to reuse the above code
    1.23 -                    return visitClassType((ClassType)s, t);
    1.24 +                if (t.isCompound() || s.isCompound()) {
    1.25 +                    return !t.isCompound() ?
    1.26 +                            visitIntersectionType((IntersectionClassType)s, t, true) :
    1.27 +                            visitIntersectionType((IntersectionClassType)t, s, false);
    1.28                  }
    1.29  
    1.30                  if (s.tag == CLASS || s.tag == ARRAY) {
    1.31 @@ -1512,6 +1499,18 @@
    1.32                  return false;
    1.33              }
    1.34  
    1.35 +            boolean visitIntersectionType(IntersectionClassType ict, Type s, boolean reverse) {
    1.36 +                Warner warn = noWarnings;
    1.37 +                for (Type c : ict.getComponents()) {
    1.38 +                    warn.clear();
    1.39 +                    if (reverse ? !isCastable(s, c, warn) : !isCastable(c, s, warn))
    1.40 +                        return false;
    1.41 +                }
    1.42 +                if (warn.hasLint(LintCategory.UNCHECKED))
    1.43 +                    warnStack.head.warn(LintCategory.UNCHECKED);
    1.44 +                return true;
    1.45 +            }
    1.46 +
    1.47              @Override
    1.48              public Boolean visitArrayType(ArrayType t, Type s) {
    1.49                  switch (s.tag) {
    1.50 @@ -3889,11 +3888,18 @@
    1.51      }
    1.52  
    1.53      private boolean giveWarning(Type from, Type to) {
    1.54 -        Type subFrom = asSub(from, to.tsym);
    1.55 -        return to.isParameterized() &&
    1.56 -                (!(isUnbounded(to) ||
    1.57 -                isSubtype(from, to) ||
    1.58 -                ((subFrom != null) && containsType(to.allparams(), subFrom.allparams()))));
    1.59 +        List<Type> bounds = to.isCompound() ?
    1.60 +                ((IntersectionClassType)to).getComponents() : List.of(to);
    1.61 +        for (Type b : bounds) {
    1.62 +            Type subFrom = asSub(from, b.tsym);
    1.63 +            if (b.isParameterized() &&
    1.64 +                    (!(isUnbounded(b) ||
    1.65 +                    isSubtype(from, b) ||
    1.66 +                    ((subFrom != null) && containsType(b.allparams(), subFrom.allparams()))))) {
    1.67 +                return true;
    1.68 +            }
    1.69 +        }
    1.70 +        return false;
    1.71      }
    1.72  
    1.73      private List<Type> superClosure(Type t, Type s) {

mercurial