55 import com.sun.tools.javac.util.List; |
55 import com.sun.tools.javac.util.List; |
56 import static com.sun.tools.javac.code.Flags.*; |
56 import static com.sun.tools.javac.code.Flags.*; |
57 import static com.sun.tools.javac.code.Flags.ANNOTATION; |
57 import static com.sun.tools.javac.code.Flags.ANNOTATION; |
58 import static com.sun.tools.javac.code.Flags.BLOCK; |
58 import static com.sun.tools.javac.code.Flags.BLOCK; |
59 import static com.sun.tools.javac.code.Kinds.*; |
59 import static com.sun.tools.javac.code.Kinds.*; |
60 import static com.sun.tools.javac.code.Kinds.ERRONEOUS; |
60 import static com.sun.tools.javac.code.Kinds.Kind.*; |
61 import static com.sun.tools.javac.code.TypeTag.*; |
61 import static com.sun.tools.javac.code.TypeTag.*; |
62 import static com.sun.tools.javac.code.TypeTag.WILDCARD; |
62 import static com.sun.tools.javac.code.TypeTag.WILDCARD; |
63 import static com.sun.tools.javac.tree.JCTree.Tag.*; |
63 import static com.sun.tools.javac.tree.JCTree.Tag.*; |
64 |
64 |
65 /** This is the main context-dependent analysis phase in GJC. It |
65 /** This is the main context-dependent analysis phase in GJC. It |
145 findDiamonds = options.get("findDiamond") != null && |
145 findDiamonds = options.get("findDiamond") != null && |
146 source.allowDiamond(); |
146 source.allowDiamond(); |
147 useBeforeDeclarationWarning = options.isSet("useBeforeDeclarationWarning"); |
147 useBeforeDeclarationWarning = options.isSet("useBeforeDeclarationWarning"); |
148 identifyLambdaCandidate = options.getBoolean("identifyLambdaCandidate", false); |
148 identifyLambdaCandidate = options.getBoolean("identifyLambdaCandidate", false); |
149 |
149 |
150 statInfo = new ResultInfo(NIL, Type.noType); |
150 statInfo = new ResultInfo(KindSelector.NIL, Type.noType); |
151 varInfo = new ResultInfo(VAR, Type.noType); |
151 varInfo = new ResultInfo(KindSelector.VAR, Type.noType); |
152 unknownExprInfo = new ResultInfo(VAL, Type.noType); |
152 unknownExprInfo = new ResultInfo(KindSelector.VAL, Type.noType); |
153 unknownAnyPolyInfo = new ResultInfo(VAL, Infer.anyPoly); |
153 unknownAnyPolyInfo = new ResultInfo(KindSelector.VAL, Infer.anyPoly); |
154 unknownTypeInfo = new ResultInfo(TYP, Type.noType); |
154 unknownTypeInfo = new ResultInfo(KindSelector.TYP, Type.noType); |
155 unknownTypeExprInfo = new ResultInfo(Kinds.TYP | Kinds.VAL, Type.noType); |
155 unknownTypeExprInfo = new ResultInfo(KindSelector.VAL_TYP, Type.noType); |
156 recoveryInfo = new RecoveryInfo(deferredAttr.emptyDeferredAttrContext); |
156 recoveryInfo = new RecoveryInfo(deferredAttr.emptyDeferredAttrContext); |
157 } |
157 } |
158 |
158 |
159 /** Switch: relax some constraints for retrofit mode. |
159 /** Switch: relax some constraints for retrofit mode. |
160 */ |
160 */ |
221 * |
221 * |
222 * @param tree The tree whose kind and type is checked |
222 * @param tree The tree whose kind and type is checked |
223 * @param ownkind The computed kind of the tree |
223 * @param ownkind The computed kind of the tree |
224 * @param resultInfo The expected result of the tree |
224 * @param resultInfo The expected result of the tree |
225 */ |
225 */ |
226 Type check(final JCTree tree, final Type found, final int ownkind, final ResultInfo resultInfo) { |
226 Type check(final JCTree tree, |
|
227 final Type found, |
|
228 final KindSelector ownkind, |
|
229 final ResultInfo resultInfo) { |
227 InferenceContext inferenceContext = resultInfo.checkContext.inferenceContext(); |
230 InferenceContext inferenceContext = resultInfo.checkContext.inferenceContext(); |
228 Type owntype; |
231 Type owntype; |
229 if (!found.hasTag(ERROR) && !resultInfo.pt.hasTag(METHOD) && !resultInfo.pt.hasTag(FORALL)) { |
232 if (!found.hasTag(ERROR) && !resultInfo.pt.hasTag(METHOD) && !resultInfo.pt.hasTag(FORALL)) { |
230 if ((ownkind & ~resultInfo.pkind) != 0) { |
233 if (!ownkind.subset(resultInfo.pkind)) { |
231 log.error(tree.pos(), "unexpected.type", |
234 log.error(tree.pos(), "unexpected.type", |
232 kindNames(resultInfo.pkind), |
235 resultInfo.pkind.kindNames(), |
233 kindName(ownkind)); |
236 ownkind.kindNames()); |
234 owntype = types.createErrorType(found); |
237 owntype = types.createErrorType(found); |
235 } else if (allowPoly && inferenceContext.free(found)) { |
238 } else if (allowPoly && inferenceContext.free(found)) { |
236 //delay the check if there are inference variables in the found type |
239 //delay the check if there are inference variables in the found type |
237 //this means we are dealing with a partially inferred poly expression |
240 //this means we are dealing with a partially inferred poly expression |
238 owntype = resultInfo.pt; |
241 owntype = resultInfo.pt; |
346 if (site.kind == ERR || site.kind == ABSENT_TYP) |
349 if (site.kind == ERR || site.kind == ABSENT_TYP) |
347 return site; |
350 return site; |
348 Name name = (Name)node.getIdentifier(); |
351 Name name = (Name)node.getIdentifier(); |
349 if (site.kind == PCK) { |
352 if (site.kind == PCK) { |
350 env.toplevel.packge = (PackageSymbol)site; |
353 env.toplevel.packge = (PackageSymbol)site; |
351 return rs.findIdentInPackage(env, (TypeSymbol)site, name, TYP | PCK); |
354 return rs.findIdentInPackage(env, (TypeSymbol)site, name, |
|
355 KindSelector.TYP_PCK); |
352 } else { |
356 } else { |
353 env.enclClass.sym = (ClassSymbol)site; |
357 env.enclClass.sym = (ClassSymbol)site; |
354 return rs.findMemberType(env, site.asType(), name, (TypeSymbol)site); |
358 return rs.findMemberType(env, site.asType(), name, (TypeSymbol)site); |
355 } |
359 } |
356 } |
360 } |
357 |
361 |
358 @Override @DefinedBy(Api.COMPILER_TREE) |
362 @Override @DefinedBy(Api.COMPILER_TREE) |
359 public Symbol visitIdentifier(IdentifierTree node, Env<AttrContext> env) { |
363 public Symbol visitIdentifier(IdentifierTree node, Env<AttrContext> env) { |
360 return rs.findIdent(env, (Name)node.getName(), TYP | PCK); |
364 return rs.findIdent(env, (Name)node.getName(), KindSelector.TYP_PCK); |
361 } |
365 } |
362 } |
366 } |
363 |
367 |
364 public Type coerce(Type etype, Type ttype) { |
368 public Type coerce(Type etype, Type ttype) { |
365 return cfolder.coerce(etype, ttype); |
369 return cfolder.coerce(etype, ttype); |
372 } |
376 } |
373 |
377 |
374 public Type attribImportQualifier(JCImport tree, Env<AttrContext> env) { |
378 public Type attribImportQualifier(JCImport tree, Env<AttrContext> env) { |
375 // Attribute qualifying package or class. |
379 // Attribute qualifying package or class. |
376 JCFieldAccess s = (JCFieldAccess)tree.qualid; |
380 JCFieldAccess s = (JCFieldAccess)tree.qualid; |
377 return attribTree(s.selected, |
381 return attribTree(s.selected, env, |
378 env, |
382 new ResultInfo(tree.staticImport ? |
379 new ResultInfo(tree.staticImport ? TYP : (TYP | PCK), |
383 KindSelector.TYP : KindSelector.TYP_PCK, |
380 Type.noType)); |
384 Type.noType)); |
381 } |
385 } |
382 |
386 |
383 public Env<AttrContext> attribExprToTree(JCTree expr, Env<AttrContext> env, JCTree tree) { |
387 public Env<AttrContext> attribExprToTree(JCTree expr, Env<AttrContext> env, JCTree tree) { |
384 breakTree = tree; |
388 breakTree = tree; |
621 attribStat(l.head, env); |
627 attribStat(l.head, env); |
622 } |
628 } |
623 |
629 |
624 /** Attribute the arguments in a method call, returning the method kind. |
630 /** Attribute the arguments in a method call, returning the method kind. |
625 */ |
631 */ |
626 int attribArgs(List<JCExpression> trees, Env<AttrContext> env, ListBuffer<Type> argtypes) { |
632 KindSelector attribArgs(List<JCExpression> trees, Env<AttrContext> env, ListBuffer<Type> argtypes) { |
627 int kind = VAL; |
633 boolean polykind = false; |
628 for (JCExpression arg : trees) { |
634 for (JCExpression arg : trees) { |
629 Type argtype; |
635 Type argtype; |
630 if (allowPoly && deferredAttr.isDeferred(env, arg)) { |
636 if (allowPoly && deferredAttr.isDeferred(env, arg)) { |
631 argtype = deferredAttr.new DeferredType(arg, env); |
637 argtype = deferredAttr.new DeferredType(arg, env); |
632 kind |= POLY; |
638 polykind = true; |
633 } else { |
639 } else { |
634 argtype = chk.checkNonVoid(arg, attribTree(arg, env, unknownAnyPolyInfo)); |
640 argtype = chk.checkNonVoid(arg, attribTree(arg, env, unknownAnyPolyInfo)); |
635 } |
641 } |
636 argtypes.append(argtype); |
642 argtypes.append(argtype); |
637 } |
643 } |
638 return kind; |
644 return polykind ? KindSelector.VAL_POLY : KindSelector.VAL; |
639 } |
645 } |
640 |
646 |
641 /** Attribute a type argument list, returning a list of types. |
647 /** Attribute a type argument list, returning a list of types. |
642 * Caller is responsible for calling checkRefTypes. |
648 * Caller is responsible for calling checkRefTypes. |
643 */ |
649 */ |
790 } |
796 } |
791 |
797 |
792 public void visitClassDef(JCClassDecl tree) { |
798 public void visitClassDef(JCClassDecl tree) { |
793 // Local and anonymous classes have not been entered yet, so we need to |
799 // Local and anonymous classes have not been entered yet, so we need to |
794 // do it now. |
800 // do it now. |
795 if ((env.info.scope.owner.kind & (VAR | MTH)) != 0) { |
801 if (env.info.scope.owner.kind.matches(KindSelector.VAL_MTH)) { |
796 enter.classEnter(tree, env); |
802 enter.classEnter(tree, env); |
797 } else { |
803 } else { |
798 // If this class declaration is part of a class level annotation, |
804 // If this class declaration is part of a class level annotation, |
799 // as in @MyAnno(new Object() {}) class MyClass {}, enter it in |
805 // as in @MyAnno(new Object() {}) class MyClass {}, enter it in |
800 // order to simplify later steps and allow for sensible error |
806 // order to simplify later steps and allow for sensible error |
1280 @Override |
1286 @Override |
1281 public void report(DiagnosticPosition pos, JCDiagnostic details) { |
1287 public void report(DiagnosticPosition pos, JCDiagnostic details) { |
1282 chk.basicHandler.report(pos, diags.fragment("try.not.applicable.to.type", details)); |
1288 chk.basicHandler.report(pos, diags.fragment("try.not.applicable.to.type", details)); |
1283 } |
1289 } |
1284 }; |
1290 }; |
1285 ResultInfo twrResult = new ResultInfo(VAL, syms.autoCloseableType, twrContext); |
1291 ResultInfo twrResult = |
|
1292 new ResultInfo(KindSelector.VAL, |
|
1293 syms.autoCloseableType, |
|
1294 twrContext); |
1286 if (resource.hasTag(VARDEF)) { |
1295 if (resource.hasTag(VARDEF)) { |
1287 attribStat(resource, tryEnv); |
1296 attribStat(resource, tryEnv); |
1288 twrResult.check(resource, resource.type); |
1297 twrResult.check(resource, resource.type); |
1289 |
1298 |
1290 //check that resource type cannot throw InterruptedException |
1299 //check that resource type cannot throw InterruptedException |
1312 Type ctype = attribStat(c.param, catchEnv); |
1321 Type ctype = attribStat(c.param, catchEnv); |
1313 if (TreeInfo.isMultiCatch(c)) { |
1322 if (TreeInfo.isMultiCatch(c)) { |
1314 //multi-catch parameter is implicitly marked as final |
1323 //multi-catch parameter is implicitly marked as final |
1315 c.param.sym.flags_field |= FINAL | UNION; |
1324 c.param.sym.flags_field |= FINAL | UNION; |
1316 } |
1325 } |
1317 if (c.param.sym.kind == Kinds.VAR) { |
1326 if (c.param.sym.kind == VAR) { |
1318 c.param.sym.setData(ElementKind.EXCEPTION_PARAMETER); |
1327 c.param.sym.setData(ElementKind.EXCEPTION_PARAMETER); |
1319 } |
1328 } |
1320 chk.checkType(c.param.vartype.pos(), |
1329 chk.checkType(c.param.vartype.pos(), |
1321 chk.checkClassType(c.param.vartype.pos(), ctype), |
1330 chk.checkClassType(c.param.vartype.pos(), ctype), |
1322 syms.throwableType); |
1331 syms.throwableType); |
1397 falsetype.constValue() != null && |
1406 falsetype.constValue() != null && |
1398 !owntype.hasTag(NONE)) { |
1407 !owntype.hasTag(NONE)) { |
1399 //constant folding |
1408 //constant folding |
1400 owntype = cfolder.coerce(condtype.isTrue() ? truetype : falsetype, owntype); |
1409 owntype = cfolder.coerce(condtype.isTrue() ? truetype : falsetype, owntype); |
1401 } |
1410 } |
1402 result = check(tree, owntype, VAL, resultInfo); |
1411 result = check(tree, owntype, KindSelector.VAL, resultInfo); |
1403 } |
1412 } |
1404 //where |
1413 //where |
1405 private boolean isBooleanOrNumeric(Env<AttrContext> env, JCExpression tree) { |
1414 private boolean isBooleanOrNumeric(Env<AttrContext> env, JCExpression tree) { |
1406 switch (tree.getTag()) { |
1415 switch (tree.getTag()) { |
1407 case LITERAL: return ((JCLiteral)tree).typetag.isSubRangeOf(DOUBLE) || |
1416 case LITERAL: return ((JCLiteral)tree).typetag.isSubRangeOf(DOUBLE) || |
1747 TreeInfo.setSymbol(tree.meth, sym); |
1756 TreeInfo.setSymbol(tree.meth, sym); |
1748 |
1757 |
1749 // ...and check that it is legal in the current context. |
1758 // ...and check that it is legal in the current context. |
1750 // (this will also set the tree's type) |
1759 // (this will also set the tree's type) |
1751 Type mpt = newMethodTemplate(resultInfo.pt, argtypes, typeargtypes); |
1760 Type mpt = newMethodTemplate(resultInfo.pt, argtypes, typeargtypes); |
1752 checkId(tree.meth, site, sym, localEnv, new ResultInfo(MTH, mpt)); |
1761 checkId(tree.meth, site, sym, localEnv, |
|
1762 new ResultInfo(KindSelector.MTH, mpt)); |
1753 } |
1763 } |
1754 // Otherwise, `site' is an error type and we do nothing |
1764 // Otherwise, `site' is an error type and we do nothing |
1755 } |
1765 } |
1756 result = tree.type = syms.voidType; |
1766 result = tree.type = syms.voidType; |
1757 } else { |
1767 } else { |
1758 // Otherwise, we are seeing a regular method call. |
1768 // Otherwise, we are seeing a regular method call. |
1759 // Attribute the arguments, yielding list of argument types, ... |
1769 // Attribute the arguments, yielding list of argument types, ... |
1760 int kind = attribArgs(tree.args, localEnv, argtypesBuf); |
1770 KindSelector kind = attribArgs(tree.args, localEnv, argtypesBuf); |
1761 argtypes = argtypesBuf.toList(); |
1771 argtypes = argtypesBuf.toList(); |
1762 typeargtypes = attribAnyTypes(tree.typeargs, localEnv); |
1772 typeargtypes = attribAnyTypes(tree.typeargs, localEnv); |
1763 |
1773 |
1764 // ... and attribute the method using as a prototype a methodtype |
1774 // ... and attribute the method using as a prototype a methodtype |
1765 // whose formal argument types is exactly the list of actual |
1775 // whose formal argument types is exactly the list of actual |
1780 |
1790 |
1781 chk.checkRefTypes(tree.typeargs, typeargtypes); |
1791 chk.checkRefTypes(tree.typeargs, typeargtypes); |
1782 |
1792 |
1783 // Check that value of resulting type is admissible in the |
1793 // Check that value of resulting type is admissible in the |
1784 // current context. Also, capture the return type |
1794 // current context. Also, capture the return type |
1785 result = check(tree, capture(restype), VAL, resultInfo); |
1795 result = check(tree, capture(restype), KindSelector.VAL, resultInfo); |
1786 } |
1796 } |
1787 chk.validate(tree.typeargs, localEnv); |
1797 chk.validate(tree.typeargs, localEnv); |
1788 } |
1798 } |
1789 //where |
1799 //where |
1790 Type adjustMethodReturnType(Type qualifierType, Name methodName, List<Type> argtypes, Type restype) { |
1800 Type adjustMethodReturnType(Type qualifierType, Name methodName, List<Type> argtypes, Type restype) { |
1934 rs.resolveImplicitThis(tree.pos(), env, clazztype); |
1944 rs.resolveImplicitThis(tree.pos(), env, clazztype); |
1935 } |
1945 } |
1936 |
1946 |
1937 // Attribute constructor arguments. |
1947 // Attribute constructor arguments. |
1938 ListBuffer<Type> argtypesBuf = new ListBuffer<>(); |
1948 ListBuffer<Type> argtypesBuf = new ListBuffer<>(); |
1939 int pkind = attribArgs(tree.args, localEnv, argtypesBuf); |
1949 final KindSelector pkind = |
|
1950 attribArgs(tree.args, localEnv, argtypesBuf); |
1940 List<Type> argtypes = argtypesBuf.toList(); |
1951 List<Type> argtypes = argtypesBuf.toList(); |
1941 List<Type> typeargtypes = attribTypes(tree.typeargs, localEnv); |
1952 List<Type> typeargtypes = attribTypes(tree.typeargs, localEnv); |
1942 |
1953 |
1943 // If we have made no mistakes in the class type... |
1954 // If we have made no mistakes in the class type... |
1944 if (clazztype.hasTag(CLASS)) { |
1955 if (clazztype.hasTag(CLASS)) { |
2094 |
2105 |
2095 // Reassign clazztype and recompute constructor. |
2106 // Reassign clazztype and recompute constructor. |
2096 clazztype = cdef.sym.type; |
2107 clazztype = cdef.sym.type; |
2097 Symbol sym = tree.constructor = rs.resolveConstructor( |
2108 Symbol sym = tree.constructor = rs.resolveConstructor( |
2098 tree.pos(), localEnv, clazztype, argtypes, typeargtypes); |
2109 tree.pos(), localEnv, clazztype, argtypes, typeargtypes); |
2099 Assert.check(sym.kind < AMBIGUOUS); |
2110 Assert.check(!sym.kind.isOverloadError()); |
2100 tree.constructor = sym; |
2111 tree.constructor = sym; |
2101 tree.constructorType = checkId(tree, |
2112 tree.constructorType = checkId(tree, |
2102 clazztype, |
2113 clazztype, |
2103 tree.constructor, |
2114 tree.constructor, |
2104 localEnv, |
2115 localEnv, |
2106 } |
2117 } |
2107 |
2118 |
2108 if (tree.constructor != null && tree.constructor.kind == MTH) |
2119 if (tree.constructor != null && tree.constructor.kind == MTH) |
2109 owntype = clazztype; |
2120 owntype = clazztype; |
2110 } |
2121 } |
2111 result = check(tree, owntype, VAL, resultInfo); |
2122 result = check(tree, owntype, KindSelector.VAL, resultInfo); |
2112 chk.validate(tree.typeargs, localEnv); |
2123 chk.validate(tree.typeargs, localEnv); |
2113 } |
2124 } |
2114 //where |
2125 //where |
2115 void findDiamond(Env<AttrContext> env, JCNewClass tree, Type clazztype) { |
2126 void findDiamond(Env<AttrContext> env, JCNewClass tree, Type clazztype) { |
2116 JCTypeApply ta = (JCTypeApply)tree.clazz; |
2127 JCTypeApply ta = (JCTypeApply)tree.clazz; |
2117 List<JCExpression> prevTypeargs = ta.arguments; |
2128 List<JCExpression> prevTypeargs = ta.arguments; |
2118 try { |
2129 try { |
2119 //create a 'fake' diamond AST node by removing type-argument trees |
2130 //create a 'fake' diamond AST node by removing type-argument trees |
2120 ta.arguments = List.nil(); |
2131 ta.arguments = List.nil(); |
2121 ResultInfo findDiamondResult = new ResultInfo(VAL, |
2132 ResultInfo findDiamondResult = new ResultInfo(KindSelector.VAL, |
2122 resultInfo.checkContext.inferenceContext().free(resultInfo.pt) ? Type.noType : pt()); |
2133 resultInfo.checkContext.inferenceContext().free(resultInfo.pt) ? Type.noType : pt()); |
2123 Type inferred = deferredAttr.attribSpeculative(tree, env, findDiamondResult).type; |
2134 Type inferred = deferredAttr.attribSpeculative(tree, env, findDiamondResult).type; |
2124 Type polyPt = allowPoly ? |
2135 Type polyPt = allowPoly ? |
2125 syms.objectType : |
2136 syms.objectType : |
2126 clazztype; |
2137 clazztype; |
2207 attribExprs(tree.elems, localEnv, elemtype); |
2218 attribExprs(tree.elems, localEnv, elemtype); |
2208 owntype = new ArrayType(elemtype, syms.arrayClass); |
2219 owntype = new ArrayType(elemtype, syms.arrayClass); |
2209 } |
2220 } |
2210 if (!types.isReifiable(elemtype)) |
2221 if (!types.isReifiable(elemtype)) |
2211 log.error(tree.pos(), "generic.array.creation"); |
2222 log.error(tree.pos(), "generic.array.creation"); |
2212 result = check(tree, owntype, VAL, resultInfo); |
2223 result = check(tree, owntype, KindSelector.VAL, resultInfo); |
2213 } |
2224 } |
2214 |
2225 |
2215 /* |
2226 /* |
2216 * A lambda expression can only be attributed when a target-type is available. |
2227 * A lambda expression can only be attributed when a target-type is available. |
2217 * In addition, if the target-type is that of a functional interface whose |
2228 * In addition, if the target-type is that of a functional interface whose |
2316 new ExpressionLambdaReturnContext((JCExpression)that.getBody(), resultInfo.checkContext) : |
2327 new ExpressionLambdaReturnContext((JCExpression)that.getBody(), resultInfo.checkContext) : |
2317 new FunctionalReturnContext(resultInfo.checkContext); |
2328 new FunctionalReturnContext(resultInfo.checkContext); |
2318 |
2329 |
2319 ResultInfo bodyResultInfo = lambdaType.getReturnType() == Type.recoveryType ? |
2330 ResultInfo bodyResultInfo = lambdaType.getReturnType() == Type.recoveryType ? |
2320 recoveryInfo : |
2331 recoveryInfo : |
2321 new ResultInfo(VAL, lambdaType.getReturnType(), funcContext); |
2332 new ResultInfo(KindSelector.VAL, |
|
2333 lambdaType.getReturnType(), funcContext); |
2322 localEnv.info.returnResult = bodyResultInfo; |
2334 localEnv.info.returnResult = bodyResultInfo; |
2323 |
2335 |
2324 if (that.getBodyKind() == JCLambda.BodyKind.EXPRESSION) { |
2336 if (that.getBodyKind() == JCLambda.BodyKind.EXPRESSION) { |
2325 attribTree(that.getBody(), localEnv, bodyResultInfo); |
2337 attribTree(that.getBody(), localEnv, bodyResultInfo); |
2326 } else { |
2338 } else { |
2327 JCBlock body = (JCBlock)that.body; |
2339 JCBlock body = (JCBlock)that.body; |
2328 attribStats(body.stats, localEnv); |
2340 attribStats(body.stats, localEnv); |
2329 } |
2341 } |
2330 |
2342 |
2331 result = check(that, currentTarget, VAL, resultInfo); |
2343 result = check(that, currentTarget, KindSelector.VAL, resultInfo); |
2332 |
2344 |
2333 boolean isSpeculativeRound = |
2345 boolean isSpeculativeRound = |
2334 resultInfo.checkContext.deferredAttrContext().mode == DeferredAttr.AttrMode.SPECULATIVE; |
2346 resultInfo.checkContext.deferredAttrContext().mode == DeferredAttr.AttrMode.SPECULATIVE; |
2335 |
2347 |
2336 preFlow(that); |
2348 preFlow(that); |
2347 chk.unhandled(inferredThrownTypes, thrownTypes); |
2359 chk.unhandled(inferredThrownTypes, thrownTypes); |
2348 } |
2360 } |
2349 |
2361 |
2350 checkAccessibleTypes(that, localEnv, resultInfo.checkContext.inferenceContext(), lambdaType, currentTarget); |
2362 checkAccessibleTypes(that, localEnv, resultInfo.checkContext.inferenceContext(), lambdaType, currentTarget); |
2351 } |
2363 } |
2352 result = check(that, currentTarget, VAL, resultInfo); |
2364 result = check(that, currentTarget, KindSelector.VAL, resultInfo); |
2353 } catch (Types.FunctionDescriptorLookupError ex) { |
2365 } catch (Types.FunctionDescriptorLookupError ex) { |
2354 JCDiagnostic cause = ex.getDiagnostic(); |
2366 JCDiagnostic cause = ex.getDiagnostic(); |
2355 resultInfo.checkContext.report(that, cause); |
2367 resultInfo.checkContext.report(that, cause); |
2356 result = that.type = types.createErrorType(pt()); |
2368 result = that.type = types.createErrorType(pt()); |
2357 return; |
2369 return; |
2800 resultInfo.checkContext.deferredAttrContext().mode == DeferredAttr.AttrMode.SPECULATIVE; |
2812 resultInfo.checkContext.deferredAttrContext().mode == DeferredAttr.AttrMode.SPECULATIVE; |
2801 checkReferenceCompatible(that, desc, refType, resultInfo.checkContext, isSpeculativeRound); |
2813 checkReferenceCompatible(that, desc, refType, resultInfo.checkContext, isSpeculativeRound); |
2802 if (!isSpeculativeRound) { |
2814 if (!isSpeculativeRound) { |
2803 checkAccessibleTypes(that, localEnv, resultInfo.checkContext.inferenceContext(), desc, currentTarget); |
2815 checkAccessibleTypes(that, localEnv, resultInfo.checkContext.inferenceContext(), desc, currentTarget); |
2804 } |
2816 } |
2805 result = check(that, currentTarget, VAL, resultInfo); |
2817 result = check(that, currentTarget, KindSelector.VAL, resultInfo); |
2806 } catch (Types.FunctionDescriptorLookupError ex) { |
2818 } catch (Types.FunctionDescriptorLookupError ex) { |
2807 JCDiagnostic cause = ex.getDiagnostic(); |
2819 JCDiagnostic cause = ex.getDiagnostic(); |
2808 resultInfo.checkContext.report(that, cause); |
2820 resultInfo.checkContext.report(that, cause); |
2809 result = that.type = types.createErrorType(pt()); |
2821 result = that.type = types.createErrorType(pt()); |
2810 return; |
2822 return; |
2811 } |
2823 } |
2812 } |
2824 } |
2813 //where |
2825 //where |
2814 ResultInfo memberReferenceQualifierResult(JCMemberReference tree) { |
2826 ResultInfo memberReferenceQualifierResult(JCMemberReference tree) { |
2815 //if this is a constructor reference, the expected kind must be a type |
2827 //if this is a constructor reference, the expected kind must be a type |
2816 return new ResultInfo(tree.getMode() == ReferenceMode.INVOKE ? VAL | TYP : TYP, Type.noType); |
2828 return new ResultInfo(tree.getMode() == ReferenceMode.INVOKE ? |
|
2829 KindSelector.VAL_TYP : KindSelector.TYP, |
|
2830 Type.noType); |
2817 } |
2831 } |
2818 |
2832 |
2819 |
2833 |
2820 @SuppressWarnings("fallthrough") |
2834 @SuppressWarnings("fallthrough") |
2821 void checkReferenceCompatible(JCMemberReference tree, Type descriptor, Type refType, CheckContext checkContext, boolean speculativeAttr) { |
2835 void checkReferenceCompatible(JCMemberReference tree, Type descriptor, Type refType, CheckContext checkContext, boolean speculativeAttr) { |
2910 |
2924 |
2911 public void visitParens(JCParens tree) { |
2925 public void visitParens(JCParens tree) { |
2912 Type owntype = attribTree(tree.expr, env, resultInfo); |
2926 Type owntype = attribTree(tree.expr, env, resultInfo); |
2913 result = check(tree, owntype, pkind(), resultInfo); |
2927 result = check(tree, owntype, pkind(), resultInfo); |
2914 Symbol sym = TreeInfo.symbol(tree); |
2928 Symbol sym = TreeInfo.symbol(tree); |
2915 if (sym != null && (sym.kind&(TYP|PCK)) != 0) |
2929 if (sym != null && sym.kind.matches(KindSelector.TYP_PCK)) |
2916 log.error(tree.pos(), "illegal.start.of.type"); |
2930 log.error(tree.pos(), "illegal.start.of.type"); |
2917 } |
2931 } |
2918 |
2932 |
2919 public void visitAssign(JCAssign tree) { |
2933 public void visitAssign(JCAssign tree) { |
2920 Type owntype = attribTree(tree.lhs, env.dup(tree), varInfo); |
2934 Type owntype = attribTree(tree.lhs, env.dup(tree), varInfo); |
2921 Type capturedType = capture(owntype); |
2935 Type capturedType = capture(owntype); |
2922 attribExpr(tree.rhs, env, owntype); |
2936 attribExpr(tree.rhs, env, owntype); |
2923 result = check(tree, capturedType, VAL, resultInfo); |
2937 result = check(tree, capturedType, KindSelector.VAL, resultInfo); |
2924 } |
2938 } |
2925 |
2939 |
2926 public void visitAssignop(JCAssignOp tree) { |
2940 public void visitAssignop(JCAssignOp tree) { |
2927 // Attribute arguments. |
2941 // Attribute arguments. |
2928 Type owntype = attribTree(tree.lhs, env, varInfo); |
2942 Type owntype = attribTree(tree.lhs, env, varInfo); |
2943 chk.checkDivZero(tree.rhs.pos(), operator, operand); |
2957 chk.checkDivZero(tree.rhs.pos(), operator, operand); |
2944 chk.checkCastable(tree.rhs.pos(), |
2958 chk.checkCastable(tree.rhs.pos(), |
2945 operator.type.getReturnType(), |
2959 operator.type.getReturnType(), |
2946 owntype); |
2960 owntype); |
2947 } |
2961 } |
2948 result = check(tree, owntype, VAL, resultInfo); |
2962 result = check(tree, owntype, KindSelector.VAL, resultInfo); |
2949 } |
2963 } |
2950 |
2964 |
2951 public void visitUnary(JCUnary tree) { |
2965 public void visitUnary(JCUnary tree) { |
2952 // Attribute arguments. |
2966 // Attribute arguments. |
2953 Type argtype = (tree.getTag().isIncOrDecUnaryOp()) |
2967 Type argtype = (tree.getTag().isIncOrDecUnaryOp()) |
2972 if (ctype != null) { |
2986 if (ctype != null) { |
2973 owntype = cfolder.coerce(ctype, owntype); |
2987 owntype = cfolder.coerce(ctype, owntype); |
2974 } |
2988 } |
2975 } |
2989 } |
2976 } |
2990 } |
2977 result = check(tree, owntype, VAL, resultInfo); |
2991 result = check(tree, owntype, KindSelector.VAL, resultInfo); |
2978 } |
2992 } |
2979 |
2993 |
2980 public void visitBinary(JCBinary tree) { |
2994 public void visitBinary(JCBinary tree) { |
2981 // Attribute arguments. |
2995 // Attribute arguments. |
2982 Type left = chk.checkNonVoid(tree.lhs.pos(), attribExpr(tree.lhs, env)); |
2996 Type left = chk.checkNonVoid(tree.lhs.pos(), attribExpr(tree.lhs, env)); |
2983 Type right = chk.checkNonVoid(tree.lhs.pos(), attribExpr(tree.rhs, env)); |
2997 Type right = chk.checkNonVoid(tree.lhs.pos(), attribExpr(tree.rhs, env)); |
2984 |
|
2985 // Find operator. |
2998 // Find operator. |
2986 Symbol operator = tree.operator = |
2999 Symbol operator = tree.operator = |
2987 rs.resolveBinaryOperator(tree.pos(), tree.getTag(), env, left, right); |
3000 rs.resolveBinaryOperator(tree.pos(), tree.getTag(), env, left, right); |
2988 |
3001 |
2989 Type owntype = types.createErrorType(tree.type); |
3002 Type owntype = types.createErrorType(tree.type); |
3032 final ResultInfo castInfo; |
3045 final ResultInfo castInfo; |
3033 JCExpression expr = TreeInfo.skipParens(tree.expr); |
3046 JCExpression expr = TreeInfo.skipParens(tree.expr); |
3034 boolean isPoly = allowPoly && (expr.hasTag(LAMBDA) || expr.hasTag(REFERENCE)); |
3047 boolean isPoly = allowPoly && (expr.hasTag(LAMBDA) || expr.hasTag(REFERENCE)); |
3035 if (isPoly) { |
3048 if (isPoly) { |
3036 //expression is a poly - we need to propagate target type info |
3049 //expression is a poly - we need to propagate target type info |
3037 castInfo = new ResultInfo(VAL, clazztype, new Check.NestedCheckContext(resultInfo.checkContext) { |
3050 castInfo = new ResultInfo(KindSelector.VAL, clazztype, |
|
3051 new Check.NestedCheckContext(resultInfo.checkContext) { |
3038 @Override |
3052 @Override |
3039 public boolean compatible(Type found, Type req, Warner warn) { |
3053 public boolean compatible(Type found, Type req, Warner warn) { |
3040 return types.isCastable(found, req, warn); |
3054 return types.isCastable(found, req, warn); |
3041 } |
3055 } |
3042 }); |
3056 }); |
3046 } |
3060 } |
3047 Type exprtype = attribTree(tree.expr, localEnv, castInfo); |
3061 Type exprtype = attribTree(tree.expr, localEnv, castInfo); |
3048 Type owntype = isPoly ? clazztype : chk.checkCastable(tree.expr.pos(), exprtype, clazztype); |
3062 Type owntype = isPoly ? clazztype : chk.checkCastable(tree.expr.pos(), exprtype, clazztype); |
3049 if (exprtype.constValue() != null) |
3063 if (exprtype.constValue() != null) |
3050 owntype = cfolder.coerce(exprtype, owntype); |
3064 owntype = cfolder.coerce(exprtype, owntype); |
3051 result = check(tree, capture(owntype), VAL, resultInfo); |
3065 result = check(tree, capture(owntype), KindSelector.VAL, resultInfo); |
3052 if (!isPoly) |
3066 if (!isPoly) |
3053 chk.checkRedundantCast(localEnv, tree); |
3067 chk.checkRedundantCast(localEnv, tree); |
3054 } |
3068 } |
3055 |
3069 |
3056 public void visitTypeTest(JCInstanceOf tree) { |
3070 public void visitTypeTest(JCInstanceOf tree) { |
3057 Type exprtype = chk.checkNullOrRefType( |
3071 Type exprtype = chk.checkNullOrRefType( |
3058 tree.expr.pos(), attribExpr(tree.expr, env)); |
3072 tree.expr.pos(), attribExpr(tree.expr, env)); |
3059 Type clazztype = attribType(tree.clazz, env); |
3073 Type clazztype = attribType(tree.clazz, env); |
3060 if (!clazztype.hasTag(TYPEVAR)) { |
3074 if (!clazztype.hasTag(TYPEVAR)) { |
3061 clazztype = chk.checkClassOrArrayType(tree.clazz.pos(), clazztype); |
3075 clazztype = chk.checkClassOrArrayType(tree.clazz.pos(), clazztype); |
3062 } |
3076 } |
3063 if (!clazztype.isErroneous() && !types.isReifiable(clazztype)) { |
3077 if (!clazztype.isErroneous() && !types.isReifiable(clazztype)) { |
3064 log.error(tree.clazz.pos(), "illegal.generic.type.for.instof"); |
3078 log.error(tree.clazz.pos(), "illegal.generic.type.for.instof"); |
3065 clazztype = types.createErrorType(clazztype); |
3079 clazztype = types.createErrorType(clazztype); |
3066 } |
3080 } |
3067 chk.validate(tree.clazz, env, false); |
3081 chk.validate(tree.clazz, env, false); |
3068 chk.checkCastable(tree.expr.pos(), exprtype, clazztype); |
3082 chk.checkCastable(tree.expr.pos(), exprtype, clazztype); |
3069 result = check(tree, syms.booleanType, VAL, resultInfo); |
3083 result = check(tree, syms.booleanType, KindSelector.VAL, resultInfo); |
3070 } |
3084 } |
3071 |
3085 |
3072 public void visitIndexed(JCArrayAccess tree) { |
3086 public void visitIndexed(JCArrayAccess tree) { |
3073 Type owntype = types.createErrorType(tree.type); |
3087 Type owntype = types.createErrorType(tree.type); |
3074 Type atype = attribExpr(tree.indexed, env); |
3088 Type atype = attribExpr(tree.indexed, env); |
3075 attribExpr(tree.index, env, syms.intType); |
3089 attribExpr(tree.index, env, syms.intType); |
3076 if (types.isArray(atype)) |
3090 if (types.isArray(atype)) |
3077 owntype = types.elemtype(atype); |
3091 owntype = types.elemtype(atype); |
3078 else if (!atype.hasTag(ERROR)) |
3092 else if (!atype.hasTag(ERROR)) |
3079 log.error(tree.pos(), "array.req.but.found", atype); |
3093 log.error(tree.pos(), "array.req.but.found", atype); |
3080 if ((pkind() & VAR) == 0) owntype = capture(owntype); |
3094 if (!pkind().contains(KindSelector.VAL)) |
3081 result = check(tree, owntype, VAR, resultInfo); |
3095 owntype = capture(owntype); |
|
3096 result = check(tree, owntype, KindSelector.VAR, resultInfo); |
3082 } |
3097 } |
3083 |
3098 |
3084 public void visitIdent(JCIdent tree) { |
3099 public void visitIdent(JCIdent tree) { |
3085 Symbol sym; |
3100 Symbol sym; |
3086 |
3101 |
3105 // members since such classes don't carry a this$n link. |
3120 // members since such classes don't carry a this$n link. |
3106 // (`noOuterThisPath'). |
3121 // (`noOuterThisPath'). |
3107 Env<AttrContext> symEnv = env; |
3122 Env<AttrContext> symEnv = env; |
3108 boolean noOuterThisPath = false; |
3123 boolean noOuterThisPath = false; |
3109 if (env.enclClass.sym.owner.kind != PCK && // we are in an inner class |
3124 if (env.enclClass.sym.owner.kind != PCK && // we are in an inner class |
3110 (sym.kind & (VAR | MTH | TYP)) != 0 && |
3125 sym.kind.matches(KindSelector.VAL_MTH) && |
3111 sym.owner.kind == TYP && |
3126 sym.owner.kind == TYP && |
3112 tree.name != names._this && tree.name != names._super) { |
3127 tree.name != names._this && tree.name != names._super) { |
3113 |
3128 |
3114 // Find environment in which identifier is defined. |
3129 // Find environment in which identifier is defined. |
3115 while (symEnv.outer != null && |
3130 while (symEnv.outer != null && |
3128 // illegal forward reference. |
3143 // illegal forward reference. |
3129 checkInit(tree, env, v, false); |
3144 checkInit(tree, env, v, false); |
3130 |
3145 |
3131 // If we are expecting a variable (as opposed to a value), check |
3146 // If we are expecting a variable (as opposed to a value), check |
3132 // that the variable is assignable in the current environment. |
3147 // that the variable is assignable in the current environment. |
3133 if (pkind() == VAR) |
3148 if (pkind() == KindSelector.VAR) |
3134 checkAssignable(tree.pos(), v, null, env); |
3149 checkAssignable(tree.pos(), v, null, env); |
3135 } |
3150 } |
3136 |
3151 |
3137 // In a constructor body, |
3152 // In a constructor body, |
3138 // if symbol is a field or instance method, check that it is |
3153 // if symbol is a field or instance method, check that it is |
3139 // not accessed before the supertype constructor is called. |
3154 // not accessed before the supertype constructor is called. |
3140 if ((symEnv.info.isSelfCall || noOuterThisPath) && |
3155 if ((symEnv.info.isSelfCall || noOuterThisPath) && |
3141 (sym.kind & (VAR | MTH)) != 0 && |
3156 sym.kind.matches(KindSelector.VAL_MTH) && |
3142 sym.owner.kind == TYP && |
3157 sym.owner.kind == TYP && |
3143 (sym.flags() & STATIC) == 0) { |
3158 (sym.flags() & STATIC) == 0) { |
3144 chk.earlyRefError(tree.pos(), sym.kind == VAR ? sym : thisSym(tree.pos(), env)); |
3159 chk.earlyRefError(tree.pos(), sym.kind == VAR ? |
|
3160 sym : thisSym(tree.pos(), env)); |
3145 } |
3161 } |
3146 Env<AttrContext> env1 = env; |
3162 Env<AttrContext> env1 = env; |
3147 if (sym.kind != ERR && sym.kind != TYP && sym.owner != null && sym.owner != env1.enclClass.sym) { |
3163 if (sym.kind != ERR && sym.kind != TYP && |
|
3164 sym.owner != null && sym.owner != env1.enclClass.sym) { |
3148 // If the found symbol is inaccessible, then it is |
3165 // If the found symbol is inaccessible, then it is |
3149 // accessed through an enclosing instance. Locate this |
3166 // accessed through an enclosing instance. Locate this |
3150 // enclosing instance: |
3167 // enclosing instance: |
3151 while (env1.outer != null && !rs.isAccessible(env, env1.enclClass.sym.type, sym)) |
3168 while (env1.outer != null && !rs.isAccessible(env, env1.enclClass.sym.type, sym)) |
3152 env1 = env1.outer; |
3169 env1 = env1.outer; |
3159 result = checkId(tree, env1.enclClass.sym.type, sym, env, resultInfo); |
3176 result = checkId(tree, env1.enclClass.sym.type, sym, env, resultInfo); |
3160 } |
3177 } |
3161 |
3178 |
3162 public void visitSelect(JCFieldAccess tree) { |
3179 public void visitSelect(JCFieldAccess tree) { |
3163 // Determine the expected kind of the qualifier expression. |
3180 // Determine the expected kind of the qualifier expression. |
3164 int skind = 0; |
3181 KindSelector skind = KindSelector.NIL; |
3165 if (tree.name == names._this || tree.name == names._super || |
3182 if (tree.name == names._this || tree.name == names._super || |
3166 tree.name == names._class) |
3183 tree.name == names._class) |
3167 { |
3184 { |
3168 skind = TYP; |
3185 skind = KindSelector.TYP; |
3169 } else { |
3186 } else { |
3170 if ((pkind() & PCK) != 0) skind = skind | PCK; |
3187 if (pkind().contains(KindSelector.PCK)) |
3171 if ((pkind() & TYP) != 0) skind = skind | TYP | PCK; |
3188 skind = KindSelector.of(skind, KindSelector.PCK); |
3172 if ((pkind() & (VAL | MTH)) != 0) skind = skind | VAL | TYP; |
3189 if (pkind().contains(KindSelector.TYP)) |
|
3190 skind = KindSelector.of(skind, KindSelector.TYP, KindSelector.PCK); |
|
3191 if (pkind().contains(KindSelector.VAL_MTH)) |
|
3192 skind = KindSelector.of(skind, KindSelector.VAL, KindSelector.TYP); |
3173 } |
3193 } |
3174 |
3194 |
3175 // Attribute the qualifier expression, and determine its symbol (if any). |
3195 // Attribute the qualifier expression, and determine its symbol (if any). |
3176 Type site = attribTree(tree.selected, env, new ResultInfo(skind, Infer.anyPoly)); |
3196 Type site = attribTree(tree.selected, env, new ResultInfo(skind, Infer.anyPoly)); |
3177 if ((pkind() & (PCK | TYP)) == 0) |
3197 if (!pkind().contains(KindSelector.TYP_PCK)) |
3178 site = capture(site); // Capture field access |
3198 site = capture(site); // Capture field access |
3179 |
3199 |
3180 // don't allow T.class T[].class, etc |
3200 // don't allow T.class T[].class, etc |
3181 if (skind == TYP) { |
3201 if (skind == KindSelector.TYP) { |
3182 Type elt = site; |
3202 Type elt = site; |
3183 while (elt.hasTag(ARRAY)) |
3203 while (elt.hasTag(ARRAY)) |
3184 elt = ((ArrayType)elt).elemtype; |
3204 elt = ((ArrayType)elt).elemtype; |
3185 if (elt.hasTag(TYPEVAR)) { |
3205 if (elt.hasTag(TYPEVAR)) { |
3186 log.error(tree.pos(), "type.var.cant.be.deref"); |
3206 log.error(tree.pos(), "type.var.cant.be.deref"); |
3200 sitesym.name == names._super; |
3220 sitesym.name == names._super; |
3201 |
3221 |
3202 // Determine the symbol represented by the selection. |
3222 // Determine the symbol represented by the selection. |
3203 env.info.pendingResolutionPhase = null; |
3223 env.info.pendingResolutionPhase = null; |
3204 Symbol sym = selectSym(tree, sitesym, site, env, resultInfo); |
3224 Symbol sym = selectSym(tree, sitesym, site, env, resultInfo); |
3205 if (sym.exists() && !isType(sym) && (pkind() & (PCK | TYP)) != 0) { |
3225 if (sym.exists() && !isType(sym) && pkind().contains(KindSelector.TYP_PCK)) { |
3206 site = capture(site); |
3226 site = capture(site); |
3207 sym = selectSym(tree, sitesym, site, env, resultInfo); |
3227 sym = selectSym(tree, sitesym, site, env, resultInfo); |
3208 } |
3228 } |
3209 boolean varArgs = env.info.lastResolveVarargs(); |
3229 boolean varArgs = env.info.lastResolveVarargs(); |
3210 tree.sym = sym; |
3230 tree.sym = sym; |
3222 // illegal forward reference. |
3242 // illegal forward reference. |
3223 checkInit(tree, env, v, true); |
3243 checkInit(tree, env, v, true); |
3224 |
3244 |
3225 // If we are expecting a variable (as opposed to a value), check |
3245 // If we are expecting a variable (as opposed to a value), check |
3226 // that the variable is assignable in the current environment. |
3246 // that the variable is assignable in the current environment. |
3227 if (pkind() == VAR) |
3247 if (pkind() == KindSelector.VAR) |
3228 checkAssignable(tree.pos(), v, tree.selected, env); |
3248 checkAssignable(tree.pos(), v, tree.selected, env); |
3229 } |
3249 } |
3230 |
3250 |
3231 if (sitesym != null && |
3251 if (sitesym != null && |
3232 sitesym.kind == VAR && |
3252 sitesym.kind == VAR && |
3237 env.info.lint.isEnabled(LintCategory.TRY)) { |
3257 env.info.lint.isEnabled(LintCategory.TRY)) { |
3238 log.warning(LintCategory.TRY, tree, "try.explicit.close.call"); |
3258 log.warning(LintCategory.TRY, tree, "try.explicit.close.call"); |
3239 } |
3259 } |
3240 |
3260 |
3241 // Disallow selecting a type from an expression |
3261 // Disallow selecting a type from an expression |
3242 if (isType(sym) && (sitesym==null || (sitesym.kind&(TYP|PCK)) == 0)) { |
3262 if (isType(sym) && (sitesym == null || !sitesym.kind.matches(KindSelector.TYP_PCK))) { |
3243 tree.type = check(tree.selected, pt(), |
3263 tree.type = check(tree.selected, pt(), |
3244 sitesym == null ? VAL : sitesym.kind, new ResultInfo(TYP|PCK, pt())); |
3264 sitesym == null ? |
|
3265 KindSelector.VAL : sitesym.kind.toSelector(), |
|
3266 new ResultInfo(KindSelector.TYP_PCK, pt())); |
3245 } |
3267 } |
3246 |
3268 |
3247 if (isType(sitesym)) { |
3269 if (isType(sitesym)) { |
3248 if (sym.name == names._this) { |
3270 if (sym.name == names._this) { |
3249 // If `C' is the currently compiled class, check that |
3271 // If `C' is the currently compiled class, check that |
3264 } |
3286 } |
3265 if (!allowStaticInterfaceMethods && sitesym.isInterface() && |
3287 if (!allowStaticInterfaceMethods && sitesym.isInterface() && |
3266 sym.isStatic() && sym.kind == MTH) { |
3288 sym.isStatic() && sym.kind == MTH) { |
3267 log.error(tree.pos(), "static.intf.method.invoke.not.supported.in.source", sourceName); |
3289 log.error(tree.pos(), "static.intf.method.invoke.not.supported.in.source", sourceName); |
3268 } |
3290 } |
3269 } else if (sym.kind != ERR && (sym.flags() & STATIC) != 0 && sym.name != names._class) { |
3291 } else if (sym.kind != ERR && |
|
3292 (sym.flags() & STATIC) != 0 && |
|
3293 sym.name != names._class) { |
3270 // If the qualified item is not a type and the selected item is static, report |
3294 // If the qualified item is not a type and the selected item is static, report |
3271 // a warning. Make allowance for the class of an array type e.g. Object[].class) |
3295 // a warning. Make allowance for the class of an array type e.g. Object[].class) |
3272 chk.warnStatic(tree, "static.not.qualified.by.type", Kinds.kindName(sym.kind), sym.owner); |
3296 chk.warnStatic(tree, "static.not.qualified.by.type", |
|
3297 sym.kind.kindName(), sym.owner); |
3273 } |
3298 } |
3274 |
3299 |
3275 // If we are selecting an instance member via a `super', ... |
3300 // If we are selecting an instance member via a `super', ... |
3276 if (env.info.selectSuper && (sym.flags() & STATIC) == 0) { |
3301 if (env.info.selectSuper && (sym.flags() & STATIC) == 0) { |
3277 |
3302 |
3328 return new VarSymbol( |
3353 return new VarSymbol( |
3329 STATIC | PUBLIC | FINAL, names._class, t, site.tsym); |
3354 STATIC | PUBLIC | FINAL, names._class, t, site.tsym); |
3330 } else { |
3355 } else { |
3331 // We are seeing a plain identifier as selector. |
3356 // We are seeing a plain identifier as selector. |
3332 Symbol sym = rs.findIdentInType(env, site, name, resultInfo.pkind); |
3357 Symbol sym = rs.findIdentInType(env, site, name, resultInfo.pkind); |
3333 if ((resultInfo.pkind & ERRONEOUS) == 0) |
|
3334 sym = rs.accessBase(sym, pos, location, site, name, true); |
3358 sym = rs.accessBase(sym, pos, location, site, name, true); |
3335 return sym; |
3359 return sym; |
3336 } |
3360 } |
3337 case WILDCARD: |
3361 case WILDCARD: |
3338 throw new AssertionError(tree); |
3362 throw new AssertionError(tree); |
3436 Type checkMethodIdInternal(JCTree tree, |
3460 Type checkMethodIdInternal(JCTree tree, |
3437 Type site, |
3461 Type site, |
3438 Symbol sym, |
3462 Symbol sym, |
3439 Env<AttrContext> env, |
3463 Env<AttrContext> env, |
3440 ResultInfo resultInfo) { |
3464 ResultInfo resultInfo) { |
3441 if ((resultInfo.pkind & POLY) != 0) { |
3465 if (resultInfo.pkind.contains(KindSelector.POLY)) { |
3442 Type pt = resultInfo.pt.map(deferredAttr.new RecoveryDeferredTypeMap(AttrMode.SPECULATIVE, sym, env.info.pendingResolutionPhase)); |
3466 Type pt = resultInfo.pt.map(deferredAttr.new RecoveryDeferredTypeMap(AttrMode.SPECULATIVE, sym, env.info.pendingResolutionPhase)); |
3443 Type owntype = checkIdInternal(tree, site, sym, pt, env, resultInfo); |
3467 Type owntype = checkIdInternal(tree, site, sym, pt, env, resultInfo); |
3444 resultInfo.pt.map(deferredAttr.new RecoveryDeferredTypeMap(AttrMode.CHECK, sym, env.info.pendingResolutionPhase)); |
3468 resultInfo.pt.map(deferredAttr.new RecoveryDeferredTypeMap(AttrMode.CHECK, sym, env.info.pendingResolutionPhase)); |
3445 return owntype; |
3469 return owntype; |
3446 } else { |
3470 } else { |
3501 case VAR: |
3525 case VAR: |
3502 VarSymbol v = (VarSymbol)sym; |
3526 VarSymbol v = (VarSymbol)sym; |
3503 // Test (4): if symbol is an instance field of a raw type, |
3527 // Test (4): if symbol is an instance field of a raw type, |
3504 // which is being assigned to, issue an unchecked warning if |
3528 // which is being assigned to, issue an unchecked warning if |
3505 // its type changes under erasure. |
3529 // its type changes under erasure. |
3506 if (resultInfo.pkind == VAR && |
3530 if (resultInfo.pkind == KindSelector.VAR && |
3507 v.owner.kind == TYP && |
3531 v.owner.kind == TYP && |
3508 (v.flags() & STATIC) == 0 && |
3532 (v.flags() & STATIC) == 0 && |
3509 (site.hasTag(CLASS) || site.hasTag(TYPEVAR))) { |
3533 (site.hasTag(CLASS) || site.hasTag(TYPEVAR))) { |
3510 Type s = types.asOuterSuper(site, v.owner); |
3534 Type s = types.asOuterSuper(site, v.owner); |
3511 if (s != null && |
3535 if (s != null && |
3557 chk.checkProfile(tree.pos(), sym); |
3581 chk.checkProfile(tree.pos(), sym); |
3558 } |
3582 } |
3559 |
3583 |
3560 // Test (3): if symbol is a variable, check that its type and |
3584 // Test (3): if symbol is a variable, check that its type and |
3561 // kind are compatible with the prototype and protokind. |
3585 // kind are compatible with the prototype and protokind. |
3562 return check(tree, owntype, sym.kind, resultInfo); |
3586 return check(tree, owntype, sym.kind.toSelector(), resultInfo); |
3563 } |
3587 } |
3564 |
3588 |
3565 /** Check that variable is initialized and evaluate the variable's |
3589 /** Check that variable is initialized and evaluate the variable's |
3566 * initializer, if not yet done. Also check that variable is not |
3590 * initializer, if not yet done. Also check that variable is not |
3567 * referenced before it is defined. |
3591 * referenced before it is defined. |
3797 return types.createErrorType(site); |
3821 return types.createErrorType(site); |
3798 } |
3822 } |
3799 } |
3823 } |
3800 |
3824 |
3801 public void visitLiteral(JCLiteral tree) { |
3825 public void visitLiteral(JCLiteral tree) { |
3802 result = check( |
3826 result = check(tree, litType(tree.typetag).constType(tree.value), |
3803 tree, litType(tree.typetag).constType(tree.value), VAL, resultInfo); |
3827 KindSelector.VAL, resultInfo); |
3804 } |
3828 } |
3805 //where |
3829 //where |
3806 /** Return the type of a literal with given type tag. |
3830 /** Return the type of a literal with given type tag. |
3807 */ |
3831 */ |
3808 Type litType(TypeTag tag) { |
3832 Type litType(TypeTag tag) { |
3809 return (tag == CLASS) ? syms.stringType : syms.typeOfTag[tag.ordinal()]; |
3833 return (tag == CLASS) ? syms.stringType : syms.typeOfTag[tag.ordinal()]; |
3810 } |
3834 } |
3811 |
3835 |
3812 public void visitTypeIdent(JCPrimitiveTypeTree tree) { |
3836 public void visitTypeIdent(JCPrimitiveTypeTree tree) { |
3813 result = check(tree, syms.typeOfTag[tree.typetag.ordinal()], TYP, resultInfo); |
3837 result = check(tree, syms.typeOfTag[tree.typetag.ordinal()], KindSelector.TYP, resultInfo); |
3814 } |
3838 } |
3815 |
3839 |
3816 public void visitTypeArray(JCArrayTypeTree tree) { |
3840 public void visitTypeArray(JCArrayTypeTree tree) { |
3817 Type etype = attribType(tree.elemtype, env); |
3841 Type etype = attribType(tree.elemtype, env); |
3818 Type type = new ArrayType(etype, syms.arrayClass); |
3842 Type type = new ArrayType(etype, syms.arrayClass); |
3819 result = check(tree, type, TYP, resultInfo); |
3843 result = check(tree, type, KindSelector.TYP, resultInfo); |
3820 } |
3844 } |
3821 |
3845 |
3822 /** Visitor method for parameterized types. |
3846 /** Visitor method for parameterized types. |
3823 * Bound checking is left until later, since types are attributed |
3847 * Bound checking is left until later, since types are attributed |
3824 * before supertype structure is completely known |
3848 * before supertype structure is completely known |
3873 log.error(tree.pos(), "type.doesnt.take.params", clazztype.tsym); |
3897 log.error(tree.pos(), "type.doesnt.take.params", clazztype.tsym); |
3874 } |
3898 } |
3875 owntype = types.createErrorType(tree.type); |
3899 owntype = types.createErrorType(tree.type); |
3876 } |
3900 } |
3877 } |
3901 } |
3878 result = check(tree, owntype, TYP, resultInfo); |
3902 result = check(tree, owntype, KindSelector.TYP, resultInfo); |
3879 } |
3903 } |
3880 |
3904 |
3881 public void visitTypeUnion(JCTypeUnion tree) { |
3905 public void visitTypeUnion(JCTypeUnion tree) { |
3882 ListBuffer<Type> multicatchTypes = new ListBuffer<>(); |
3906 ListBuffer<Type> multicatchTypes = new ListBuffer<>(); |
3883 ListBuffer<Type> all_multicatchTypes = null; // lazy, only if needed |
3907 ListBuffer<Type> all_multicatchTypes = null; // lazy, only if needed |
3910 all_multicatchTypes.appendList(multicatchTypes); |
3934 all_multicatchTypes.appendList(multicatchTypes); |
3911 } |
3935 } |
3912 all_multicatchTypes.append(ctype); |
3936 all_multicatchTypes.append(ctype); |
3913 } |
3937 } |
3914 } |
3938 } |
3915 Type t = check(tree, types.lub(multicatchTypes.toList()), TYP, resultInfo); |
3939 Type t = check(tree, types.lub(multicatchTypes.toList()), |
|
3940 KindSelector.TYP, resultInfo); |
3916 if (t.hasTag(CLASS)) { |
3941 if (t.hasTag(CLASS)) { |
3917 List<Type> alternatives = |
3942 List<Type> alternatives = |
3918 ((all_multicatchTypes == null) ? multicatchTypes : all_multicatchTypes).toList(); |
3943 ((all_multicatchTypes == null) ? multicatchTypes : all_multicatchTypes).toList(); |
3919 t = new UnionClassType((ClassType) t, alternatives); |
3944 t = new UnionClassType((ClassType) t, alternatives); |
3920 } |
3945 } |