131 allowEnums = source.allowEnums(); |
131 allowEnums = source.allowEnums(); |
132 allowBoxing = source.allowBoxing(); |
132 allowBoxing = source.allowBoxing(); |
133 allowCovariantReturns = source.allowCovariantReturns(); |
133 allowCovariantReturns = source.allowCovariantReturns(); |
134 allowAnonOuterThis = source.allowAnonOuterThis(); |
134 allowAnonOuterThis = source.allowAnonOuterThis(); |
135 allowStringsInSwitch = source.allowStringsInSwitch(); |
135 allowStringsInSwitch = source.allowStringsInSwitch(); |
136 allowPoly = source.allowPoly() && options.isSet("allowPoly"); |
136 allowPoly = source.allowPoly(); |
137 allowLambda = source.allowLambda(); |
137 allowLambda = source.allowLambda(); |
138 allowDefaultMethods = source.allowDefaultMethods(); |
138 allowDefaultMethods = source.allowDefaultMethods(); |
139 sourceName = source.name; |
139 sourceName = source.name; |
140 relax = (options.isSet("-retrofit") || |
140 relax = (options.isSet("-retrofit") || |
141 options.isSet("-relax")); |
141 options.isSet("-relax")); |
177 |
177 |
178 /** Switch: support covariant result types? |
178 /** Switch: support covariant result types? |
179 */ |
179 */ |
180 boolean allowCovariantReturns; |
180 boolean allowCovariantReturns; |
181 |
181 |
|
182 /** Switch: support lambda expressions ? |
|
183 */ |
|
184 boolean allowLambda; |
|
185 |
182 /** Switch: support default methods ? |
186 /** Switch: support default methods ? |
183 */ |
187 */ |
184 boolean allowDefaultMethods; |
188 boolean allowDefaultMethods; |
185 |
|
186 /** Switch: support lambda expressions ? |
|
187 */ |
|
188 boolean allowLambda; |
|
189 |
189 |
190 /** Switch: allow references to surrounding object from anonymous |
190 /** Switch: allow references to surrounding object from anonymous |
191 * objects during constructor call? |
191 * objects during constructor call? |
192 */ |
192 */ |
193 boolean allowAnonOuterThis; |
193 boolean allowAnonOuterThis; |
522 } |
522 } |
523 |
523 |
524 protected ResultInfo dup(Type newPt) { |
524 protected ResultInfo dup(Type newPt) { |
525 return new ResultInfo(pkind, newPt, checkContext); |
525 return new ResultInfo(pkind, newPt, checkContext); |
526 } |
526 } |
|
527 |
|
528 protected ResultInfo dup(CheckContext newContext) { |
|
529 return new ResultInfo(pkind, pt, newContext); |
|
530 } |
527 } |
531 } |
528 |
532 |
529 class RecoveryInfo extends ResultInfo { |
533 class RecoveryInfo extends ResultInfo { |
530 |
534 |
531 public RecoveryInfo(final DeferredAttr.DeferredAttrContext deferredAttrContext) { |
535 public RecoveryInfo(final DeferredAttr.DeferredAttrContext deferredAttrContext) { |
593 ResultInfo prevResult = this.resultInfo; |
597 ResultInfo prevResult = this.resultInfo; |
594 try { |
598 try { |
595 this.env = env; |
599 this.env = env; |
596 this.resultInfo = resultInfo; |
600 this.resultInfo = resultInfo; |
597 tree.accept(this); |
601 tree.accept(this); |
598 if (tree == breakTree) |
602 if (tree == breakTree && |
|
603 resultInfo.checkContext.deferredAttrContext().mode == AttrMode.CHECK) { |
599 throw new BreakAttr(env); |
604 throw new BreakAttr(env); |
|
605 } |
600 return result; |
606 return result; |
601 } catch (CompletionFailure ex) { |
607 } catch (CompletionFailure ex) { |
602 tree.type = syms.errType; |
608 tree.type = syms.errType; |
603 return chk.completionError(tree.pos(), ex); |
609 return chk.completionError(tree.pos(), ex); |
604 } finally { |
610 } finally { |
901 // for attributing the method. |
907 // for attributing the method. |
902 Env<AttrContext> localEnv = memberEnter.methodEnv(tree, env); |
908 Env<AttrContext> localEnv = memberEnter.methodEnv(tree, env); |
903 |
909 |
904 localEnv.info.lint = lint; |
910 localEnv.info.lint = lint; |
905 |
911 |
906 if (isDefaultMethod && types.overridesObjectMethod(m)) { |
912 if (isDefaultMethod && types.overridesObjectMethod(m.enclClass(), m)) { |
907 log.error(tree, "default.overrides.object.member", m.name, Kinds.kindName(m.location()), m.location()); |
913 log.error(tree, "default.overrides.object.member", m.name, Kinds.kindName(m.location()), m.location()); |
908 } |
914 } |
909 |
915 |
910 // Enter all type parameters into the local method scope. |
916 // Enter all type parameters into the local method scope. |
911 for (List<JCTypeParameter> l = tree.typarams; l.nonEmpty(); l = l.tail) |
917 for (List<JCTypeParameter> l = tree.typarams; l.nonEmpty(); l = l.tail) |
1388 pt().hasTag(NONE) && pt() != Type.recoveryType || |
1394 pt().hasTag(NONE) && pt() != Type.recoveryType || |
1389 isBooleanOrNumeric(env, tree); |
1395 isBooleanOrNumeric(env, tree); |
1390 |
1396 |
1391 if (!standaloneConditional && resultInfo.pt.hasTag(VOID)) { |
1397 if (!standaloneConditional && resultInfo.pt.hasTag(VOID)) { |
1392 //cannot get here (i.e. it means we are returning from void method - which is already an error) |
1398 //cannot get here (i.e. it means we are returning from void method - which is already an error) |
|
1399 resultInfo.checkContext.report(tree, diags.fragment("conditional.target.cant.be.void")); |
1393 result = tree.type = types.createErrorType(resultInfo.pt); |
1400 result = tree.type = types.createErrorType(resultInfo.pt); |
1394 return; |
1401 return; |
1395 } |
1402 } |
1396 |
1403 |
1397 ResultInfo condInfo = standaloneConditional ? |
1404 ResultInfo condInfo = standaloneConditional ? |
1398 unknownExprInfo : |
1405 unknownExprInfo : |
1399 new ResultInfo(VAL, pt(), new Check.NestedCheckContext(resultInfo.checkContext) { |
1406 resultInfo.dup(new Check.NestedCheckContext(resultInfo.checkContext) { |
1400 //this will use enclosing check context to check compatibility of |
1407 //this will use enclosing check context to check compatibility of |
1401 //subexpression against target type; if we are in a method check context, |
1408 //subexpression against target type; if we are in a method check context, |
1402 //depending on whether boxing is allowed, we could have incompatibilities |
1409 //depending on whether boxing is allowed, we could have incompatibilities |
1403 @Override |
1410 @Override |
1404 public void report(DiagnosticPosition pos, JCDiagnostic details) { |
1411 public void report(DiagnosticPosition pos, JCDiagnostic details) { |
1417 owntype = cfolder.coerce(condtype.isTrue() ? truetype : falsetype, owntype); |
1424 owntype = cfolder.coerce(condtype.isTrue() ? truetype : falsetype, owntype); |
1418 } |
1425 } |
1419 result = check(tree, owntype, VAL, resultInfo); |
1426 result = check(tree, owntype, VAL, resultInfo); |
1420 } |
1427 } |
1421 //where |
1428 //where |
1422 @SuppressWarnings("fallthrough") |
|
1423 private boolean isBooleanOrNumeric(Env<AttrContext> env, JCExpression tree) { |
1429 private boolean isBooleanOrNumeric(Env<AttrContext> env, JCExpression tree) { |
1424 switch (tree.getTag()) { |
1430 switch (tree.getTag()) { |
1425 case LITERAL: return ((JCLiteral)tree).typetag.isSubRangeOf(DOUBLE) || |
1431 case LITERAL: return ((JCLiteral)tree).typetag.isSubRangeOf(DOUBLE) || |
1426 ((JCLiteral)tree).typetag == BOOLEAN; |
1432 ((JCLiteral)tree).typetag == BOOLEAN || |
|
1433 ((JCLiteral)tree).typetag == BOT; |
1427 case LAMBDA: case REFERENCE: return false; |
1434 case LAMBDA: case REFERENCE: return false; |
1428 case PARENS: return isBooleanOrNumeric(env, ((JCParens)tree).expr); |
1435 case PARENS: return isBooleanOrNumeric(env, ((JCParens)tree).expr); |
1429 case CONDEXPR: |
1436 case CONDEXPR: |
1430 JCConditional condTree = (JCConditional)tree; |
1437 JCConditional condTree = (JCConditional)tree; |
1431 return isBooleanOrNumeric(env, condTree.truepart) && |
1438 return isBooleanOrNumeric(env, condTree.truepart) && |
1610 } else { |
1617 } else { |
1611 // Attribute return expression, if it exists, and check that |
1618 // Attribute return expression, if it exists, and check that |
1612 // it conforms to result type of enclosing method. |
1619 // it conforms to result type of enclosing method. |
1613 if (tree.expr != null) { |
1620 if (tree.expr != null) { |
1614 if (env.info.returnResult.pt.hasTag(VOID)) { |
1621 if (env.info.returnResult.pt.hasTag(VOID)) { |
1615 log.error(tree.expr.pos(), |
1622 env.info.returnResult.checkContext.report(tree.expr.pos(), |
1616 "cant.ret.val.from.meth.decl.void"); |
1623 diags.fragment("unexpected.ret.val")); |
1617 } |
1624 } |
1618 attribTree(tree.expr, env, env.info.returnResult); |
1625 attribTree(tree.expr, env, env.info.returnResult); |
1619 } else if (!env.info.returnResult.pt.hasTag(VOID)) { |
1626 } else if (!env.info.returnResult.pt.hasTag(VOID)) { |
1620 log.error(tree.pos(), "missing.ret.val"); |
1627 env.info.returnResult.checkContext.report(tree.pos(), |
|
1628 diags.fragment("missing.ret.val")); |
1621 } |
1629 } |
1622 } |
1630 } |
1623 result = null; |
1631 result = null; |
1624 } |
1632 } |
1625 |
1633 |
1626 public void visitThrow(JCThrow tree) { |
1634 public void visitThrow(JCThrow tree) { |
1627 attribExpr(tree.expr, env, syms.throwableType); |
1635 Type owntype = attribExpr(tree.expr, env, allowPoly ? Type.noType : syms.throwableType); |
|
1636 if (allowPoly) { |
|
1637 chk.checkType(tree, owntype, syms.throwableType); |
|
1638 } |
1628 result = null; |
1639 result = null; |
1629 } |
1640 } |
1630 |
1641 |
1631 public void visitAssert(JCAssert tree) { |
1642 public void visitAssert(JCAssert tree) { |
1632 attribExpr(tree.cond, env, syms.booleanType); |
1643 attribExpr(tree.cond, env, syms.booleanType); |
2066 ta.arguments = List.nil(); |
2077 ta.arguments = List.nil(); |
2067 ResultInfo findDiamondResult = new ResultInfo(VAL, |
2078 ResultInfo findDiamondResult = new ResultInfo(VAL, |
2068 resultInfo.checkContext.inferenceContext().free(resultInfo.pt) ? Type.noType : pt()); |
2079 resultInfo.checkContext.inferenceContext().free(resultInfo.pt) ? Type.noType : pt()); |
2069 Type inferred = deferredAttr.attribSpeculative(tree, env, findDiamondResult).type; |
2080 Type inferred = deferredAttr.attribSpeculative(tree, env, findDiamondResult).type; |
2070 if (!inferred.isErroneous() && |
2081 if (!inferred.isErroneous() && |
2071 types.isAssignable(inferred, pt().hasTag(NONE) ? syms.objectType : pt(), Warner.noWarnings)) { |
2082 types.isAssignable(inferred, pt().hasTag(NONE) ? syms.objectType : pt(), types.noWarnings)) { |
2072 String key = types.isSameType(clazztype, inferred) ? |
2083 String key = types.isSameType(clazztype, inferred) ? |
2073 "diamond.redundant.args" : |
2084 "diamond.redundant.args" : |
2074 "diamond.redundant.args.1"; |
2085 "diamond.redundant.args.1"; |
2075 log.warning(tree.clazz.pos(), key, clazztype, inferred); |
2086 log.warning(tree.clazz.pos(), key, clazztype, inferred); |
2076 } |
2087 } |
2170 result = that.type = types.createErrorType(pt()); |
2181 result = that.type = types.createErrorType(pt()); |
2171 return; |
2182 return; |
2172 } |
2183 } |
2173 //create an environment for attribution of the lambda expression |
2184 //create an environment for attribution of the lambda expression |
2174 final Env<AttrContext> localEnv = lambdaEnv(that, env); |
2185 final Env<AttrContext> localEnv = lambdaEnv(that, env); |
2175 boolean needsRecovery = resultInfo.checkContext.deferredAttrContext() == deferredAttr.emptyDeferredAttrContext || |
2186 boolean needsRecovery = |
2176 resultInfo.checkContext.deferredAttrContext().mode == DeferredAttr.AttrMode.CHECK; |
2187 resultInfo.checkContext.deferredAttrContext().mode == DeferredAttr.AttrMode.CHECK; |
2177 try { |
2188 try { |
2178 List<Type> explicitParamTypes = null; |
2189 List<Type> explicitParamTypes = null; |
2179 if (TreeInfo.isExplicitLambda(that)) { |
2190 if (TreeInfo.isExplicitLambda(that)) { |
2180 //attribute lambda parameters |
2191 //attribute lambda parameters |
2181 attribStats(that.params, localEnv); |
2192 attribStats(that.params, localEnv); |
2182 explicitParamTypes = TreeInfo.types(that.params); |
2193 explicitParamTypes = TreeInfo.types(that.params); |
2183 } |
2194 } |
2184 |
2195 |
2185 Type target = infer.instantiateFunctionalInterface(that, pt(), explicitParamTypes, resultInfo.checkContext); |
2196 Type target; |
2186 Type lambdaType = (target == Type.recoveryType) ? |
2197 Type lambdaType; |
2187 fallbackDescriptorType(that) : |
2198 if (pt() != Type.recoveryType) { |
2188 types.findDescriptorType(target); |
2199 target = infer.instantiateFunctionalInterface(that, pt(), explicitParamTypes, resultInfo.checkContext); |
|
2200 lambdaType = types.findDescriptorType(target); |
|
2201 chk.checkFunctionalInterface(that, target); |
|
2202 } else { |
|
2203 target = Type.recoveryType; |
|
2204 lambdaType = fallbackDescriptorType(that); |
|
2205 } |
2189 |
2206 |
2190 if (!TreeInfo.isExplicitLambda(that)) { |
2207 if (!TreeInfo.isExplicitLambda(that)) { |
2191 //add param type info in the AST |
2208 //add param type info in the AST |
2192 List<Type> actuals = lambdaType.getParameterTypes(); |
2209 List<Type> actuals = lambdaType.getParameterTypes(); |
2193 List<JCVariableDecl> params = that.params; |
2210 List<JCVariableDecl> params = that.params; |
2248 flow.analyzeLambda(env, that, make, isSpeculativeRound); |
2265 flow.analyzeLambda(env, that, make, isSpeculativeRound); |
2249 |
2266 |
2250 checkLambdaCompatible(that, lambdaType, resultInfo.checkContext, isSpeculativeRound); |
2267 checkLambdaCompatible(that, lambdaType, resultInfo.checkContext, isSpeculativeRound); |
2251 |
2268 |
2252 if (!isSpeculativeRound) { |
2269 if (!isSpeculativeRound) { |
2253 checkAccessibleFunctionalDescriptor(that, localEnv, resultInfo.checkContext.inferenceContext(), lambdaType); |
2270 checkAccessibleTypes(that, localEnv, resultInfo.checkContext.inferenceContext(), lambdaType, target); |
2254 } |
2271 } |
2255 result = check(that, target, VAL, resultInfo); |
2272 result = check(that, target, VAL, resultInfo); |
2256 } catch (Types.FunctionDescriptorLookupError ex) { |
2273 } catch (Types.FunctionDescriptorLookupError ex) { |
2257 JCDiagnostic cause = ex.getDiagnostic(); |
2274 JCDiagnostic cause = ex.getDiagnostic(); |
2258 resultInfo.checkContext.report(that, cause); |
2275 resultInfo.checkContext.report(that, cause); |
2283 Assert.error("Cannot get here!"); |
2300 Assert.error("Cannot get here!"); |
2284 } |
2301 } |
2285 return null; |
2302 return null; |
2286 } |
2303 } |
2287 |
2304 |
2288 private void checkAccessibleFunctionalDescriptor(final DiagnosticPosition pos, |
2305 private void checkAccessibleTypes(final DiagnosticPosition pos, final Env<AttrContext> env, final InferenceContext inferenceContext, final Type... ts) { |
2289 final Env<AttrContext> env, final InferenceContext inferenceContext, final Type desc) { |
2306 checkAccessibleTypes(pos, env, inferenceContext, List.from(ts)); |
2290 if (inferenceContext.free(desc)) { |
2307 } |
2291 inferenceContext.addFreeTypeListener(List.of(desc), new FreeTypeListener() { |
2308 |
|
2309 private void checkAccessibleTypes(final DiagnosticPosition pos, final Env<AttrContext> env, final InferenceContext inferenceContext, final List<Type> ts) { |
|
2310 if (inferenceContext.free(ts)) { |
|
2311 inferenceContext.addFreeTypeListener(ts, new FreeTypeListener() { |
2292 @Override |
2312 @Override |
2293 public void typesInferred(InferenceContext inferenceContext) { |
2313 public void typesInferred(InferenceContext inferenceContext) { |
2294 checkAccessibleFunctionalDescriptor(pos, env, inferenceContext, inferenceContext.asInstType(desc, types)); |
2314 checkAccessibleTypes(pos, env, inferenceContext, inferenceContext.asInstTypes(ts, types)); |
2295 } |
2315 } |
2296 }); |
2316 }); |
2297 } else { |
2317 } else { |
2298 chk.checkAccessibleFunctionalDescriptor(pos, env, desc); |
2318 for (Type t : ts) { |
|
2319 rs.checkAccessibleType(env, t); |
|
2320 } |
2299 } |
2321 } |
2300 } |
2322 } |
2301 |
2323 |
2302 /** |
2324 /** |
2303 * Lambda/method reference have a special check context that ensures |
2325 * Lambda/method reference have a special check context that ensures |
2409 List<Type> typeargtypes = null; |
2431 List<Type> typeargtypes = null; |
2410 if (that.typeargs != null) { |
2432 if (that.typeargs != null) { |
2411 typeargtypes = attribTypes(that.typeargs, localEnv); |
2433 typeargtypes = attribTypes(that.typeargs, localEnv); |
2412 } |
2434 } |
2413 |
2435 |
2414 Type target = infer.instantiateFunctionalInterface(that, pt(), null, resultInfo.checkContext); |
2436 Type target; |
2415 Type desc = (target == Type.recoveryType) ? |
2437 Type desc; |
2416 fallbackDescriptorType(that) : |
2438 if (pt() != Type.recoveryType) { |
2417 types.findDescriptorType(target); |
2439 target = infer.instantiateFunctionalInterface(that, pt(), null, resultInfo.checkContext); |
|
2440 desc = types.findDescriptorType(target); |
|
2441 chk.checkFunctionalInterface(that, target); |
|
2442 } else { |
|
2443 target = Type.recoveryType; |
|
2444 desc = fallbackDescriptorType(that); |
|
2445 } |
2418 |
2446 |
2419 List<Type> argtypes = desc.getParameterTypes(); |
2447 List<Type> argtypes = desc.getParameterTypes(); |
2420 |
2448 |
2421 boolean allowBoxing = |
2449 boolean allowBoxing = |
2422 resultInfo.checkContext.deferredAttrContext() == deferredAttr.emptyDeferredAttrContext || |
|
2423 resultInfo.checkContext.deferredAttrContext().phase.isBoxingRequired(); |
2450 resultInfo.checkContext.deferredAttrContext().phase.isBoxingRequired(); |
2424 Pair<Symbol, Resolve.ReferenceLookupHelper> refResult = rs.resolveMemberReference(that.pos(), localEnv, that, |
2451 Pair<Symbol, Resolve.ReferenceLookupHelper> refResult = rs.resolveMemberReference(that.pos(), localEnv, that, |
2425 that.expr.type, that.name, argtypes, typeargtypes, allowBoxing); |
2452 that.expr.type, that.name, argtypes, typeargtypes, allowBoxing); |
2426 |
2453 |
2427 Symbol refSym = refResult.fst; |
2454 Symbol refSym = refResult.fst; |
2453 JCDiagnostic.DiagnosticType.FRAGMENT : JCDiagnostic.DiagnosticType.ERROR; |
2480 JCDiagnostic.DiagnosticType.FRAGMENT : JCDiagnostic.DiagnosticType.ERROR; |
2454 |
2481 |
2455 JCDiagnostic diag = diags.create(diagKind, log.currentSource(), that, |
2482 JCDiagnostic diag = diags.create(diagKind, log.currentSource(), that, |
2456 "invalid.mref", Kinds.kindName(that.getMode()), detailsDiag); |
2483 "invalid.mref", Kinds.kindName(that.getMode()), detailsDiag); |
2457 |
2484 |
2458 if (targetError) { |
2485 if (targetError && target == Type.recoveryType) { |
2459 resultInfo.checkContext.report(that, diag); |
2486 //a target error doesn't make sense during recovery stage |
|
2487 //as we don't know what actual parameter types are |
|
2488 result = that.type = target; |
|
2489 return; |
2460 } else { |
2490 } else { |
2461 log.report(diag); |
2491 if (targetError) { |
2462 } |
2492 resultInfo.checkContext.report(that, diag); |
2463 result = that.type = types.createErrorType(target); |
2493 } else { |
2464 return; |
2494 log.report(diag); |
|
2495 } |
|
2496 result = that.type = types.createErrorType(target); |
|
2497 return; |
|
2498 } |
2465 } |
2499 } |
2466 |
2500 |
2467 if (desc.getReturnType() == Type.recoveryType) { |
2501 if (desc.getReturnType() == Type.recoveryType) { |
2468 // stop here |
2502 // stop here |
2469 result = that.type = types.createErrorType(target); |
2503 result = that.type = target; |
2470 return; |
2504 return; |
2471 } |
2505 } |
2472 |
2506 |
2473 that.sym = refSym.baseSymbol(); |
2507 that.sym = refSym.baseSymbol(); |
2474 that.kind = lookupHelper.referenceKind(that.sym); |
2508 that.kind = lookupHelper.referenceKind(that.sym); |
2490 //is a no-op (as this has been taken care during method applicability) |
2524 //is a no-op (as this has been taken care during method applicability) |
2491 boolean isSpeculativeRound = |
2525 boolean isSpeculativeRound = |
2492 resultInfo.checkContext.deferredAttrContext().mode == DeferredAttr.AttrMode.SPECULATIVE; |
2526 resultInfo.checkContext.deferredAttrContext().mode == DeferredAttr.AttrMode.SPECULATIVE; |
2493 checkReferenceCompatible(that, desc, refType, resultInfo.checkContext, isSpeculativeRound); |
2527 checkReferenceCompatible(that, desc, refType, resultInfo.checkContext, isSpeculativeRound); |
2494 if (!isSpeculativeRound) { |
2528 if (!isSpeculativeRound) { |
2495 checkAccessibleFunctionalDescriptor(that, localEnv, resultInfo.checkContext.inferenceContext(), desc); |
2529 checkAccessibleTypes(that, localEnv, resultInfo.checkContext.inferenceContext(), desc, target); |
2496 } |
2530 } |
2497 result = check(that, target, VAL, resultInfo); |
2531 result = check(that, target, VAL, resultInfo); |
2498 } catch (Types.FunctionDescriptorLookupError ex) { |
2532 } catch (Types.FunctionDescriptorLookupError ex) { |
2499 JCDiagnostic cause = ex.getDiagnostic(); |
2533 JCDiagnostic cause = ex.getDiagnostic(); |
2500 resultInfo.checkContext.report(that, cause); |
2534 resultInfo.checkContext.report(that, cause); |
2524 incompatibleReturnType = null; |
2558 incompatibleReturnType = null; |
2525 } |
2559 } |
2526 |
2560 |
2527 if (!returnType.hasTag(VOID) && !resType.hasTag(VOID)) { |
2561 if (!returnType.hasTag(VOID) && !resType.hasTag(VOID)) { |
2528 if (resType.isErroneous() || |
2562 if (resType.isErroneous() || |
2529 new LambdaReturnContext(checkContext).compatible(resType, returnType, Warner.noWarnings)) { |
2563 new LambdaReturnContext(checkContext).compatible(resType, returnType, types.noWarnings)) { |
2530 incompatibleReturnType = null; |
2564 incompatibleReturnType = null; |
2531 } |
2565 } |
2532 } |
2566 } |
2533 |
2567 |
2534 if (incompatibleReturnType != null) { |
2568 if (incompatibleReturnType != null) { |
3037 Type checkId(JCTree tree, |
3071 Type checkId(JCTree tree, |
3038 Type site, |
3072 Type site, |
3039 Symbol sym, |
3073 Symbol sym, |
3040 Env<AttrContext> env, |
3074 Env<AttrContext> env, |
3041 ResultInfo resultInfo) { |
3075 ResultInfo resultInfo) { |
3042 Type pt = resultInfo.pt.hasTag(FORALL) || resultInfo.pt.hasTag(METHOD) ? |
3076 return (resultInfo.pt.hasTag(FORALL) || resultInfo.pt.hasTag(METHOD)) ? |
3043 resultInfo.pt.map(deferredAttr.new DeferredTypeMap(AttrMode.SPECULATIVE, sym, env.info.pendingResolutionPhase)) : |
3077 checkMethodId(tree, site, sym, env, resultInfo) : |
3044 resultInfo.pt; |
3078 checkIdInternal(tree, site, sym, resultInfo.pt, env, resultInfo); |
3045 |
3079 } |
3046 DeferredAttr.DeferredTypeMap recoveryMap = |
3080 |
3047 deferredAttr.new RecoveryDeferredTypeMap(AttrMode.CHECK, sym, env.info.pendingResolutionPhase); |
3081 Type checkMethodId(JCTree tree, |
3048 |
3082 Type site, |
|
3083 Symbol sym, |
|
3084 Env<AttrContext> env, |
|
3085 ResultInfo resultInfo) { |
|
3086 boolean isPolymorhicSignature = |
|
3087 sym.kind == MTH && ((MethodSymbol)sym.baseSymbol()).isSignaturePolymorphic(types); |
|
3088 return isPolymorhicSignature ? |
|
3089 checkSigPolyMethodId(tree, site, sym, env, resultInfo) : |
|
3090 checkMethodIdInternal(tree, site, sym, env, resultInfo); |
|
3091 } |
|
3092 |
|
3093 Type checkSigPolyMethodId(JCTree tree, |
|
3094 Type site, |
|
3095 Symbol sym, |
|
3096 Env<AttrContext> env, |
|
3097 ResultInfo resultInfo) { |
|
3098 //recover original symbol for signature polymorphic methods |
|
3099 checkMethodIdInternal(tree, site, sym.baseSymbol(), env, resultInfo); |
|
3100 env.info.pendingResolutionPhase = Resolve.MethodResolutionPhase.BASIC; |
|
3101 return sym.type; |
|
3102 } |
|
3103 |
|
3104 Type checkMethodIdInternal(JCTree tree, |
|
3105 Type site, |
|
3106 Symbol sym, |
|
3107 Env<AttrContext> env, |
|
3108 ResultInfo resultInfo) { |
|
3109 Type pt = resultInfo.pt.map(deferredAttr.new RecoveryDeferredTypeMap(AttrMode.SPECULATIVE, sym, env.info.pendingResolutionPhase)); |
|
3110 Type owntype = checkIdInternal(tree, site, sym, pt, env, resultInfo); |
|
3111 resultInfo.pt.map(deferredAttr.new RecoveryDeferredTypeMap(AttrMode.CHECK, sym, env.info.pendingResolutionPhase)); |
|
3112 return owntype; |
|
3113 } |
|
3114 |
|
3115 Type checkIdInternal(JCTree tree, |
|
3116 Type site, |
|
3117 Symbol sym, |
|
3118 Type pt, |
|
3119 Env<AttrContext> env, |
|
3120 ResultInfo resultInfo) { |
3049 if (pt.isErroneous()) { |
3121 if (pt.isErroneous()) { |
3050 Type.map(resultInfo.pt.getParameterTypes(), recoveryMap); |
|
3051 return types.createErrorType(site); |
3122 return types.createErrorType(site); |
3052 } |
3123 } |
3053 Type owntype; // The computed type of this identifier occurrence. |
3124 Type owntype; // The computed type of this identifier occurrence. |
3054 switch (sym.kind) { |
3125 switch (sym.kind) { |
3055 case TYP: |
3126 case TYP: |
3286 "unchecked.call.mbr.of.raw.type", |
3356 "unchecked.call.mbr.of.raw.type", |
3287 sym, s); |
3357 sym, s); |
3288 } |
3358 } |
3289 } |
3359 } |
3290 |
3360 |
3291 if (env.info.defaultSuperCallSite != null && |
3361 if (env.info.defaultSuperCallSite != null) { |
3292 !types.interfaceCandidates(env.enclClass.type, (MethodSymbol)sym, true).contains(sym)) { |
3362 for (Type sup : types.interfaces(env.enclClass.type).prepend(types.supertype((env.enclClass.type)))) { |
3293 Symbol ovSym = null; |
3363 if (!sup.tsym.isSubClass(sym.enclClass(), types) || |
3294 for (MethodSymbol msym : types.interfaceCandidates(env.enclClass.type, (MethodSymbol)sym, true)) { |
3364 types.isSameType(sup, env.info.defaultSuperCallSite)) continue; |
3295 if (msym.overrides(sym, msym.enclClass(), types, true)) { |
3365 List<MethodSymbol> icand_sup = |
3296 for (Type i : types.interfaces(env.enclClass.type)) { |
3366 types.interfaceCandidates(sup, (MethodSymbol)sym); |
3297 if (i.tsym.isSubClass(msym.owner, types)) { |
3367 if (icand_sup.nonEmpty() && |
3298 ovSym = i.tsym; |
3368 icand_sup.head != sym && |
3299 break; |
3369 icand_sup.head.overrides(sym, icand_sup.head.enclClass(), types, true)) { |
3300 } |
3370 log.error(env.tree.pos(), "illegal.default.super.call", env.info.defaultSuperCallSite, |
3301 } |
3371 diags.fragment("overridden.default", sym, sup)); |
3302 } |
3372 break; |
3303 } |
3373 } |
3304 log.error(env.tree.pos(), "illegal.default.super.call", env.info.defaultSuperCallSite, |
3374 } |
3305 diags.fragment("overridden.default", sym, ovSym)); |
3375 env.info.defaultSuperCallSite = null; |
3306 } |
3376 } |
3307 |
3377 |
3308 // Compute the identifier's instantiated type. |
3378 // Compute the identifier's instantiated type. |
3309 // For methods, we need to compute the instance type by |
3379 // For methods, we need to compute the instance type by |
3310 // Resolve.instantiate from the symbol's type as well as |
3380 // Resolve.instantiate from the symbol's type as well as |