118 allowVarargs = source.allowVarargs(); |
118 allowVarargs = source.allowVarargs(); |
119 allowAnnotations = source.allowAnnotations(); |
119 allowAnnotations = source.allowAnnotations(); |
120 allowCovariantReturns = source.allowCovariantReturns(); |
120 allowCovariantReturns = source.allowCovariantReturns(); |
121 allowSimplifiedVarargs = source.allowSimplifiedVarargs(); |
121 allowSimplifiedVarargs = source.allowSimplifiedVarargs(); |
122 allowDefaultMethods = source.allowDefaultMethods(); |
122 allowDefaultMethods = source.allowDefaultMethods(); |
123 allowStrictMethodClashCheck = source.allowStrictMethodClashCheck() && |
123 allowStrictMethodClashCheck = source.allowStrictMethodClashCheck(); |
124 options.isSet("strictMethodClashCheck"); //pre-lambda guard |
|
125 complexInference = options.isSet("complexinference"); |
124 complexInference = options.isSet("complexinference"); |
126 warnOnSyntheticConflicts = options.isSet("warnOnSyntheticConflicts"); |
125 warnOnSyntheticConflicts = options.isSet("warnOnSyntheticConflicts"); |
127 suppressAbortOnBadClassFile = options.isSet("suppressAbortOnBadClassFile"); |
126 suppressAbortOnBadClassFile = options.isSet("suppressAbortOnBadClassFile"); |
128 enableSunApiLintControl = options.isSet("enableSunApiLintControl"); |
127 enableSunApiLintControl = options.isSet("enableSunApiLintControl"); |
129 |
128 |
449 public Warner checkWarner(DiagnosticPosition pos, Type found, Type req); |
448 public Warner checkWarner(DiagnosticPosition pos, Type found, Type req); |
450 |
449 |
451 public Infer.InferenceContext inferenceContext(); |
450 public Infer.InferenceContext inferenceContext(); |
452 |
451 |
453 public DeferredAttr.DeferredAttrContext deferredAttrContext(); |
452 public DeferredAttr.DeferredAttrContext deferredAttrContext(); |
454 |
|
455 public boolean allowBoxing(); |
|
456 } |
453 } |
457 |
454 |
458 /** |
455 /** |
459 * This class represent a check context that is nested within another check |
456 * This class represent a check context that is nested within another check |
460 * context - useful to check sub-expressions. The default behavior simply |
457 * context - useful to check sub-expressions. The default behavior simply |
512 return infer.emptyContext; |
505 return infer.emptyContext; |
513 } |
506 } |
514 |
507 |
515 public DeferredAttrContext deferredAttrContext() { |
508 public DeferredAttrContext deferredAttrContext() { |
516 return deferredAttr.emptyDeferredAttrContext; |
509 return deferredAttr.emptyDeferredAttrContext; |
517 } |
|
518 |
|
519 public boolean allowBoxing() { |
|
520 return true; |
|
521 } |
510 } |
522 }; |
511 }; |
523 |
512 |
524 /** Check that a given type is assignable to a given proto-type. |
513 /** Check that a given type is assignable to a given proto-type. |
525 * If it is, return the type, otherwise return errType. |
514 * If it is, return the type, otherwise return errType. |
623 return true; |
612 return true; |
624 } else if (!a.hasTag(WILDCARD)) { |
613 } else if (!a.hasTag(WILDCARD)) { |
625 a = types.upperBound(a); |
614 a = types.upperBound(a); |
626 return types.isSubtype(a, bound); |
615 return types.isSubtype(a, bound); |
627 } else if (a.isExtendsBound()) { |
616 } else if (a.isExtendsBound()) { |
628 return types.isCastable(bound, types.upperBound(a), Warner.noWarnings); |
617 return types.isCastable(bound, types.upperBound(a), types.noWarnings); |
629 } else if (a.isSuperBound()) { |
618 } else if (a.isSuperBound()) { |
630 return !types.notSoftSubtype(types.lowerBound(a), bound); |
619 return !types.notSoftSubtype(types.lowerBound(a), bound); |
631 } |
620 } |
632 return true; |
621 return true; |
633 } |
622 } |
907 !isTrustMeAllowedOnMethod(sym))) { |
896 !isTrustMeAllowedOnMethod(sym))) { |
908 warnUnchecked(env.tree.pos(), |
897 warnUnchecked(env.tree.pos(), |
909 "unchecked.generic.array.creation", |
898 "unchecked.generic.array.creation", |
910 argtype); |
899 argtype); |
911 } |
900 } |
912 Type elemtype = types.elemtype(argtype); |
901 if (!((MethodSymbol)sym.baseSymbol()).isSignaturePolymorphic(types)) { |
913 switch (tree.getTag()) { |
902 Type elemtype = types.elemtype(argtype); |
914 case APPLY: |
903 switch (tree.getTag()) { |
915 ((JCMethodInvocation) tree).varargsElement = elemtype; |
904 case APPLY: |
916 break; |
905 ((JCMethodInvocation) tree).varargsElement = elemtype; |
917 case NEWCLASS: |
906 break; |
918 ((JCNewClass) tree).varargsElement = elemtype; |
907 case NEWCLASS: |
919 break; |
908 ((JCNewClass) tree).varargsElement = elemtype; |
920 case REFERENCE: |
909 break; |
921 ((JCMemberReference) tree).varargsElement = elemtype; |
910 case REFERENCE: |
922 break; |
911 ((JCMemberReference) tree).varargsElement = elemtype; |
923 default: |
912 break; |
924 throw new AssertionError(""+tree); |
913 default: |
|
914 throw new AssertionError(""+tree); |
|
915 } |
925 } |
916 } |
926 } |
917 } |
927 return owntype; |
918 return owntype; |
928 } |
919 } |
929 //where |
920 //where |
935 && types.isSubtype(actual, types.supertype(formal)) |
926 && types.isSubtype(actual, types.supertype(formal)) |
936 && types.isSubtypeUnchecked(actual, types.interfaces(formal), warn)) |
927 && types.isSubtypeUnchecked(actual, types.interfaces(formal), warn)) |
937 return; |
928 return; |
938 } |
929 } |
939 |
930 |
940 void checkAccessibleFunctionalDescriptor(DiagnosticPosition pos, Env<AttrContext> env, Type desc) { |
|
941 AccessChecker accessChecker = new AccessChecker(env); |
|
942 //check args accessibility (only if implicit parameter types) |
|
943 for (Type arg : desc.getParameterTypes()) { |
|
944 if (!accessChecker.visit(arg)) { |
|
945 log.error(pos, "cant.access.arg.type.in.functional.desc", arg); |
|
946 return; |
|
947 } |
|
948 } |
|
949 //check return type accessibility |
|
950 if (!accessChecker.visit(desc.getReturnType())) { |
|
951 log.error(pos, "cant.access.return.in.functional.desc", desc.getReturnType()); |
|
952 return; |
|
953 } |
|
954 //check thrown types accessibility |
|
955 for (Type thrown : desc.getThrownTypes()) { |
|
956 if (!accessChecker.visit(thrown)) { |
|
957 log.error(pos, "cant.access.thrown.in.functional.desc", thrown); |
|
958 return; |
|
959 } |
|
960 } |
|
961 } |
|
962 |
|
963 class AccessChecker extends Types.UnaryVisitor<Boolean> { |
|
964 |
|
965 Env<AttrContext> env; |
|
966 |
|
967 AccessChecker(Env<AttrContext> env) { |
|
968 this.env = env; |
|
969 } |
|
970 |
|
971 Boolean visit(List<Type> ts) { |
|
972 for (Type t : ts) { |
|
973 if (!visit(t)) |
|
974 return false; |
|
975 } |
|
976 return true; |
|
977 } |
|
978 |
|
979 public Boolean visitType(Type t, Void s) { |
|
980 return true; |
|
981 } |
|
982 |
|
983 @Override |
|
984 public Boolean visitArrayType(ArrayType t, Void s) { |
|
985 return visit(t.elemtype); |
|
986 } |
|
987 |
|
988 @Override |
|
989 public Boolean visitClassType(ClassType t, Void s) { |
|
990 return rs.isAccessible(env, t, true) && |
|
991 visit(t.getTypeArguments()); |
|
992 } |
|
993 |
|
994 @Override |
|
995 public Boolean visitWildcardType(WildcardType t, Void s) { |
|
996 return visit(t.type); |
|
997 } |
|
998 }; |
|
999 /** |
931 /** |
1000 * Check that type 't' is a valid instantiation of a generic class |
932 * Check that type 't' is a valid instantiation of a generic class |
1001 * (see JLS 4.5) |
933 * (see JLS 4.5) |
1002 * |
934 * |
1003 * @param t class type to be checked |
935 * @param t class type to be checked |
1917 Type rt2 = types.subst(st2.getReturnType(), tvars2, tvars1); |
1849 Type rt2 = types.subst(st2.getReturnType(), tvars2, tvars1); |
1918 boolean compat = |
1850 boolean compat = |
1919 types.isSameType(rt1, rt2) || |
1851 types.isSameType(rt1, rt2) || |
1920 !rt1.isPrimitiveOrVoid() && |
1852 !rt1.isPrimitiveOrVoid() && |
1921 !rt2.isPrimitiveOrVoid() && |
1853 !rt2.isPrimitiveOrVoid() && |
1922 (types.covariantReturnType(rt1, rt2, Warner.noWarnings) || |
1854 (types.covariantReturnType(rt1, rt2, types.noWarnings) || |
1923 types.covariantReturnType(rt2, rt1, Warner.noWarnings)) || |
1855 types.covariantReturnType(rt2, rt1, types.noWarnings)) || |
1924 checkCommonOverriderIn(s1,s2,site); |
1856 checkCommonOverriderIn(s1,s2,site); |
1925 if (!compat) { |
1857 if (!compat) { |
1926 log.error(pos, "types.incompatible.diff.ret", |
1858 log.error(pos, "types.incompatible.diff.ret", |
1927 t1, t2, s2.name + |
1859 t1, t2, s2.name + |
1928 "(" + types.memberType(t2, s2).getParameterTypes() + ")"); |
1860 "(" + types.memberType(t2, s2).getParameterTypes() + ")"); |
1963 Type rt13 = types.subst(st3.getReturnType(), tvars3, tvars1); |
1895 Type rt13 = types.subst(st3.getReturnType(), tvars3, tvars1); |
1964 Type rt23 = types.subst(st3.getReturnType(), tvars3, tvars2); |
1896 Type rt23 = types.subst(st3.getReturnType(), tvars3, tvars2); |
1965 boolean compat = |
1897 boolean compat = |
1966 !rt13.isPrimitiveOrVoid() && |
1898 !rt13.isPrimitiveOrVoid() && |
1967 !rt23.isPrimitiveOrVoid() && |
1899 !rt23.isPrimitiveOrVoid() && |
1968 (types.covariantReturnType(rt13, rt1, Warner.noWarnings) && |
1900 (types.covariantReturnType(rt13, rt1, types.noWarnings) && |
1969 types.covariantReturnType(rt23, rt2, Warner.noWarnings)); |
1901 types.covariantReturnType(rt23, rt2, types.noWarnings)); |
1970 if (compat) |
1902 if (compat) |
1971 return true; |
1903 return true; |
1972 } |
1904 } |
1973 } |
1905 } |
1974 } |
1906 } |
2278 ((ClassType)c.type).supertype_field = types.createErrorType((ClassSymbol)st.tsym, Type.noType); |
2210 ((ClassType)c.type).supertype_field = types.createErrorType((ClassSymbol)st.tsym, Type.noType); |
2279 c.type = types.createErrorType(c, c.type); |
2211 c.type = types.createErrorType(c, c.type); |
2280 c.flags_field |= ACYCLIC; |
2212 c.flags_field |= ACYCLIC; |
2281 } |
2213 } |
2282 |
2214 |
|
2215 /** |
|
2216 * Check that functional interface methods would make sense when seen |
|
2217 * from the perspective of the implementing class |
|
2218 */ |
|
2219 void checkFunctionalInterface(JCTree tree, Type funcInterface) { |
|
2220 ClassType c = new ClassType(Type.noType, List.<Type>nil(), null); |
|
2221 ClassSymbol csym = new ClassSymbol(0, names.empty, c, syms.noSymbol); |
|
2222 c.interfaces_field = List.of(funcInterface); |
|
2223 c.supertype_field = syms.objectType; |
|
2224 c.tsym = csym; |
|
2225 csym.members_field = new Scope(csym); |
|
2226 csym.completer = null; |
|
2227 checkImplementations(tree, csym, csym); |
|
2228 } |
|
2229 |
2283 /** Check that all methods which implement some |
2230 /** Check that all methods which implement some |
2284 * method conform to the method they implement. |
2231 * method conform to the method they implement. |
2285 * @param tree The class definition whose members are checked. |
2232 * @param tree The class definition whose members are checked. |
2286 */ |
2233 */ |
2287 void checkImplementations(JCClassDecl tree) { |
2234 void checkImplementations(JCClassDecl tree) { |
2288 checkImplementations(tree, tree.sym); |
2235 checkImplementations(tree, tree.sym, tree.sym); |
2289 } |
2236 } |
2290 //where |
2237 //where |
2291 /** Check that all methods which implement some |
2238 /** Check that all methods which implement some |
2292 * method in `ic' conform to the method they implement. |
2239 * method in `ic' conform to the method they implement. |
2293 */ |
2240 */ |
2294 void checkImplementations(JCClassDecl tree, ClassSymbol ic) { |
2241 void checkImplementations(JCTree tree, ClassSymbol origin, ClassSymbol ic) { |
2295 ClassSymbol origin = tree.sym; |
|
2296 for (List<Type> l = types.closure(ic.type); l.nonEmpty(); l = l.tail) { |
2242 for (List<Type> l = types.closure(ic.type); l.nonEmpty(); l = l.tail) { |
2297 ClassSymbol lc = (ClassSymbol)l.head.tsym; |
2243 ClassSymbol lc = (ClassSymbol)l.head.tsym; |
2298 if ((allowGenerics || origin != lc) && (lc.flags() & ABSTRACT) != 0) { |
2244 if ((allowGenerics || origin != lc) && (lc.flags() & ABSTRACT) != 0) { |
2299 for (Scope.Entry e=lc.members().elems; e != null; e=e.sibling) { |
2245 for (Scope.Entry e=lc.members().elems; e != null; e=e.sibling) { |
2300 if (e.sym.kind == MTH && |
2246 if (e.sym.kind == MTH && |