diff options
Diffstat (limited to 'src/share/classes/com/sun/tools/javac/comp/Resolve.java')
-rw-r--r-- | src/share/classes/com/sun/tools/javac/comp/Resolve.java | 69 |
1 files changed, 42 insertions, 27 deletions
diff --git a/src/share/classes/com/sun/tools/javac/comp/Resolve.java b/src/share/classes/com/sun/tools/javac/comp/Resolve.java index 87a29320..7b3d3e26 100644 --- a/src/share/classes/com/sun/tools/javac/comp/Resolve.java +++ b/src/share/classes/com/sun/tools/javac/comp/Resolve.java @@ -271,7 +271,7 @@ public class Resolve { * the one of its outer environment */ protected static boolean isStatic(Env<AttrContext> env) { - return env.info.staticLevel > env.outer.info.staticLevel; + return env.outer != null && env.info.staticLevel > env.outer.info.staticLevel; } /** An environment is an "initializer" if it is a constructor or @@ -717,7 +717,8 @@ public class Resolve { Warner warn) { //should we expand formals? boolean useVarargs = deferredAttrContext.phase.isVarargsRequired(); - List<JCExpression> trees = TreeInfo.args(env.tree); + JCTree callTree = treeForDiagnostics(env); + List<JCExpression> trees = TreeInfo.args(callTree); //inference context used during this method check InferenceContext inferenceContext = deferredAttrContext.inferenceContext; @@ -726,7 +727,7 @@ public class Resolve { if (varargsFormal == null && argtypes.size() != formals.size()) { - reportMC(env.tree, MethodCheckDiag.ARITY_MISMATCH, inferenceContext); // not enough args + reportMC(callTree, MethodCheckDiag.ARITY_MISMATCH, inferenceContext); // not enough args } while (argtypes.nonEmpty() && formals.head != varargsFormal) { @@ -738,7 +739,7 @@ public class Resolve { } if (formals.head != varargsFormal) { - reportMC(env.tree, MethodCheckDiag.ARITY_MISMATCH, inferenceContext); // not enough args + reportMC(callTree, MethodCheckDiag.ARITY_MISMATCH, inferenceContext); // not enough args } if (useVarargs) { @@ -754,6 +755,11 @@ public class Resolve { } } + // where + private JCTree treeForDiagnostics(Env<AttrContext> env) { + return env.info.preferredTreeForDiagnostics != null ? env.info.preferredTreeForDiagnostics : env.tree; + } + /** * Does the actual argument conforms to the corresponding formal? */ @@ -836,20 +842,19 @@ public class Resolve { List<Type> formals, Warner warn) { super.argumentsAcceptable(env, deferredAttrContext, argtypes, formals, warn); - //should we expand formals? + // should we check varargs element type accessibility? if (deferredAttrContext.phase.isVarargsRequired()) { - Type typeToCheck = null; - if (!checkVarargsAccessAfterResolution) { - typeToCheck = types.elemtype(formals.last()); - } else if (deferredAttrContext.mode == AttrMode.CHECK) { - typeToCheck = types.erasure(types.elemtype(formals.last())); - } - if (typeToCheck != null) { - varargsAccessible(env, typeToCheck, deferredAttrContext.inferenceContext); + if (deferredAttrContext.mode == AttrMode.CHECK || !checkVarargsAccessAfterResolution) { + varargsAccessible(env, types.elemtype(formals.last()), deferredAttrContext.inferenceContext); } } } + /** + * Test that the runtime array element type corresponding to 't' is accessible. 't' should be the + * varargs element type of either the method invocation type signature (after inference completes) + * or the method declaration signature (before inference completes). + */ private void varargsAccessible(final Env<AttrContext> env, final Type t, final InferenceContext inferenceContext) { if (inferenceContext.free(t)) { inferenceContext.addFreeTypeListener(List.of(t), new FreeTypeListener() { @@ -859,7 +864,7 @@ public class Resolve { } }); } else { - if (!isAccessible(env, t)) { + if (!isAccessible(env, types.erasure(t))) { Symbol location = env.enclClass.sym; reportMC(env.tree, MethodCheckDiag.INACCESSIBLE_VARARGS, inferenceContext, t, Kinds.kindName(location), location); } @@ -1829,17 +1834,23 @@ public class Resolve { boolean staticOnly = false; while (env1.outer != null) { if (isStatic(env1)) staticOnly = true; - sym = findMethod( - env1, env1.enclClass.sym.type, name, argtypes, typeargtypes, - allowBoxing, useVarargs, false); - if (sym.exists()) { - if (staticOnly && - sym.kind == MTH && - sym.owner.kind == TYP && - (sym.flags() & STATIC) == 0) return new StaticError(sym); - else return sym; - } else if (sym.kind < bestSoFar.kind) { - bestSoFar = sym; + Assert.check(env1.info.preferredTreeForDiagnostics == null); + env1.info.preferredTreeForDiagnostics = env.tree; + try { + sym = findMethod( + env1, env1.enclClass.sym.type, name, argtypes, typeargtypes, + allowBoxing, useVarargs, false); + if (sym.exists()) { + if (staticOnly && + sym.kind == MTH && + sym.owner.kind == TYP && + (sym.flags() & STATIC) == 0) return new StaticError(sym); + else return sym; + } else if (sym.kind < bestSoFar.kind) { + bestSoFar = sym; + } + } finally { + env1.info.preferredTreeForDiagnostics = null; } if ((env1.enclClass.sym.flags() & STATIC) != 0) staticOnly = true; env1 = env1.outer; @@ -4087,7 +4098,7 @@ public class Resolve { s : new MethodSymbol( s.flags(), s.name, - types.createMethodTypeWithThrown(mt, allThrown), + types.createMethodTypeWithThrown(s.type, allThrown), s.owner); } } @@ -4215,7 +4226,11 @@ public class Resolve { DiagnosticPosition preferedPos, DiagnosticSource preferredSource, DiagnosticType preferredKind, JCDiagnostic d) { JCDiagnostic cause = (JCDiagnostic)d.getArgs()[0]; - return diags.create(preferredKind, preferredSource, d.getDiagnosticPosition(), + DiagnosticPosition pos = d.getDiagnosticPosition(); + if (pos == null) { + pos = preferedPos; + } + return diags.create(preferredKind, preferredSource, pos, "prob.found.req", cause); } }); |