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

changeset 2385
856d94394294
parent 2384
327122b01a9e
child 2398
7c925f35f81c
equal deleted inserted replaced
2384:327122b01a9e 2385:856d94394294
827 } 827 }
828 return true; 828 return true;
829 } 829 }
830 830
831 // Generally, if 's' is a type variable, recur on lower bound; but 831 // Generally, if 's' is a type variable, recur on lower bound; but
832 // for alpha <: CAP, alpha should get upper bound CAP 832 // for inference variables and intersections, we need to keep 's'
833 if (!t.hasTag(UNDETVAR)) { 833 // (see JLS 4.10.2 for intersections and 18.2.3 for inference vars)
834 if (!t.hasTag(UNDETVAR) && !t.isCompound()) {
834 // TODO: JDK-8039198, bounds checking sometimes passes in a wildcard as s 835 // TODO: JDK-8039198, bounds checking sometimes passes in a wildcard as s
835 Type lower = cvarLowerBound(wildLowerBound(s)); 836 Type lower = cvarLowerBound(wildLowerBound(s));
836 if (s != lower) 837 if (s != lower)
837 return isSubtype(capture ? capture(t) : t, lower, false); 838 return isSubtype(capture ? capture(t) : t, lower, false);
838 } 839 }
917 } 918 }
918 919
919 @Override 920 @Override
920 public Boolean visitClassType(ClassType t, Type s) { 921 public Boolean visitClassType(ClassType t, Type s) {
921 Type sup = asSuper(t, s.tsym); 922 Type sup = asSuper(t, s.tsym);
922 return sup != null 923 if (sup == null) return false;
923 && sup.tsym == s.tsym 924 // If t is an intersection, sup might not be a class type
924 // You're not allowed to write 925 if (!sup.hasTag(CLASS)) return isSubtypeNoCapture(sup, s);
925 // Vector<Object> vec = new Vector<String>(); 926 return sup.tsym == s.tsym
926 // But with wildcards you can write 927 // Check type variable containment
927 // Vector<? extends Object> vec = new Vector<String>();
928 // which means that subtype checking must be done
929 // here instead of same-type checking (via containsType).
930 && (!s.isParameterized() || containsTypeRecursive(s, sup)) 928 && (!s.isParameterized() || containsTypeRecursive(s, sup))
931 && isSubtypeNoCapture(sup.getEnclosingType(), 929 && isSubtypeNoCapture(sup.getEnclosingType(),
932 s.getEnclosingType()); 930 s.getEnclosingType());
933 } 931 }
934 932
1958 public Type visitClassType(ClassType t, Symbol sym) { 1956 public Type visitClassType(ClassType t, Symbol sym) {
1959 if (t.tsym == sym) 1957 if (t.tsym == sym)
1960 return t; 1958 return t;
1961 1959
1962 Type st = supertype(t); 1960 Type st = supertype(t);
1963 if (st.hasTag(CLASS) || st.hasTag(TYPEVAR) || st.hasTag(ERROR)) { 1961 if (st.hasTag(CLASS) || st.hasTag(TYPEVAR)) {
1964 Type x = asSuper(st, sym); 1962 Type x = asSuper(st, sym);
1965 if (x != null) 1963 if (x != null)
1966 return x; 1964 return x;
1967 } 1965 }
1968 if ((sym.flags() & INTERFACE) != 0) { 1966 if ((sym.flags() & INTERFACE) != 0) {
1969 for (List<Type> l = interfaces(t); l.nonEmpty(); l = l.tail) { 1967 for (List<Type> l = interfaces(t); l.nonEmpty(); l = l.tail) {
1970 Type x = asSuper(l.head, sym); 1968 if (!l.head.hasTag(ERROR)) {
1971 if (x != null) 1969 Type x = asSuper(l.head, sym);
1972 return x; 1970 if (x != null)
1971 return x;
1972 }
1973 } 1973 }
1974 } 1974 }
1975 return null; 1975 return null;
1976 } 1976 }
1977 1977

mercurial