8075184: javac is mistakenly considering an missing enclosing instance error as an overload error

Reviewed-by: mcimadamore
This commit is contained in:
Vicente Romero 2015-03-27 10:11:21 -07:00
parent ffae4d6955
commit 38527cecd5
7 changed files with 49 additions and 43 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -66,22 +66,22 @@ public class Kinds {
MTH(Category.BASIC, KindName.METHOD, KindSelector.MTH), MTH(Category.BASIC, KindName.METHOD, KindSelector.MTH),
POLY(Category.BASIC, KindSelector.POLY), POLY(Category.BASIC, KindSelector.POLY),
ERR(Category.ERROR, KindSelector.ERR), ERR(Category.ERROR, KindSelector.ERR),
AMBIGUOUS(Category.OVERLOAD), AMBIGUOUS(Category.RESOLUTION_TARGET), // overloaded target
HIDDEN(Category.OVERLOAD), HIDDEN(Category.RESOLUTION_TARGET), // not overloaded non-target
STATICERR(Category.OVERLOAD), STATICERR(Category.RESOLUTION_TARGET), // overloaded? target
MISSING_ENCL(Category.OVERLOAD), MISSING_ENCL(Category.RESOLUTION), // not overloaded non-target
ABSENT_VAR(Category.OVERLOAD, KindName.VAR), ABSENT_VAR(Category.RESOLUTION_TARGET, KindName.VAR), // not overloaded non-target
WRONG_MTHS(Category.OVERLOAD, KindName.METHOD), WRONG_MTHS(Category.RESOLUTION_TARGET, KindName.METHOD), // overloaded target
WRONG_MTH(Category.OVERLOAD, KindName.METHOD), WRONG_MTH(Category.RESOLUTION_TARGET, KindName.METHOD), // not overloaded target
ABSENT_MTH(Category.OVERLOAD, KindName.METHOD), ABSENT_MTH(Category.RESOLUTION_TARGET, KindName.METHOD), // not overloaded non-target
ABSENT_TYP(Category.OVERLOAD, KindName.CLASS); ABSENT_TYP(Category.RESOLUTION_TARGET, KindName.CLASS); // not overloaded non-target
// There are essentially two "levels" to the Kind datatype. // There are essentially two "levels" to the Kind datatype.
// The first is a totally-ordered set of categories of // The first is a totally-ordered set of categories of
// solutions. Within each category, we have more // solutions. Within each category, we have more
// possibilities. // possibilities.
private enum Category { private enum Category {
BASIC, ERROR, OVERLOAD; BASIC, ERROR, RESOLUTION, RESOLUTION_TARGET;
} }
private final KindName kindName; private final KindName kindName;
@ -127,8 +127,12 @@ public class Kinds {
return selector.contains(kindSelectors); return selector.contains(kindSelectors);
} }
public boolean isOverloadError() { public boolean isResolutionError() {
return category == Category.OVERLOAD; return category == Category.RESOLUTION || category == Category.RESOLUTION_TARGET;
}
public boolean isResolutionTargetError() {
return category == Category.RESOLUTION_TARGET;
} }
public boolean isValid() { public boolean isValid() {

View File

@ -2109,7 +2109,7 @@ public class Attr extends JCTree.Visitor {
clazztype = cdef.sym.type; clazztype = cdef.sym.type;
Symbol sym = tree.constructor = rs.resolveConstructor( Symbol sym = tree.constructor = rs.resolveConstructor(
tree.pos(), localEnv, clazztype, argtypes, typeargtypes); tree.pos(), localEnv, clazztype, argtypes, typeargtypes);
Assert.check(!sym.kind.isOverloadError()); Assert.check(!sym.kind.isResolutionError());
tree.constructor = sym; tree.constructor = sym;
tree.constructorType = checkId(noCheckTree, tree.constructorType = checkId(noCheckTree,
clazztype, clazztype,
@ -2647,17 +2647,20 @@ public class Attr extends JCTree.Visitor {
Symbol refSym = refResult.fst; Symbol refSym = refResult.fst;
Resolve.ReferenceLookupHelper lookupHelper = refResult.snd; Resolve.ReferenceLookupHelper lookupHelper = refResult.snd;
/** this switch will need to go away and be replaced by the new RESOLUTION_TARGET testing
* JDK-8075541
*/
if (refSym.kind != MTH) { if (refSym.kind != MTH) {
boolean targetError; boolean targetError;
switch (refSym.kind) { switch (refSym.kind) {
case ABSENT_MTH: case ABSENT_MTH:
case MISSING_ENCL:
targetError = false; targetError = false;
break; break;
case WRONG_MTH: case WRONG_MTH:
case WRONG_MTHS: case WRONG_MTHS:
case AMBIGUOUS: case AMBIGUOUS:
case HIDDEN: case HIDDEN:
case MISSING_ENCL:
case STATICERR: case STATICERR:
targetError = true; targetError = true;
break; break;

View File

@ -1209,8 +1209,8 @@ public class DeferredAttr extends JCTree.Visitor {
rs.getMemberReference(tree, localEnv, mref2, rs.getMemberReference(tree, localEnv, mref2,
exprTree.type, tree.name); exprTree.type, tree.name);
tree.sym = res; tree.sym = res;
if (res.kind.isOverloadError() || if (res.kind.isResolutionTargetError() ||
res.type.hasTag(FORALL) || res.type != null && res.type.hasTag(FORALL) ||
(res.flags() & Flags.VARARGS) != 0 || (res.flags() & Flags.VARARGS) != 0 ||
(TreeInfo.isStaticSelector(exprTree, tree.name.table.names) && (TreeInfo.isStaticSelector(exprTree, tree.name.table.names) &&
exprTree.type.isRaw())) { exprTree.type.isRaw())) {

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -194,7 +194,7 @@ public class Resolve {
void reportVerboseResolutionDiagnostic(DiagnosticPosition dpos, Name name, Type site, void reportVerboseResolutionDiagnostic(DiagnosticPosition dpos, Name name, Type site,
List<Type> argtypes, List<Type> typeargtypes, Symbol bestSoFar) { List<Type> argtypes, List<Type> typeargtypes, Symbol bestSoFar) {
boolean success = !bestSoFar.kind.isOverloadError(); boolean success = !bestSoFar.kind.isResolutionError();
if (success && !verboseResolutionMode.contains(VerboseResolutionMode.SUCCESS)) { if (success && !verboseResolutionMode.contains(VerboseResolutionMode.SUCCESS)) {
return; return;
@ -1389,7 +1389,7 @@ public class Resolve {
if (currentSymbol.kind != VAR) if (currentSymbol.kind != VAR)
continue; continue;
// invariant: sym.kind == Symbol.Kind.VAR // invariant: sym.kind == Symbol.Kind.VAR
if (!bestSoFar.kind.isOverloadError() && if (!bestSoFar.kind.isResolutionError() &&
currentSymbol.owner != bestSoFar.owner) currentSymbol.owner != bestSoFar.owner)
return new AmbiguityError(bestSoFar, currentSymbol); return new AmbiguityError(bestSoFar, currentSymbol);
else if (!bestSoFar.kind.betterThan(VAR)) { else if (!bestSoFar.kind.betterThan(VAR)) {
@ -1432,11 +1432,11 @@ public class Resolve {
!sym.isInheritedIn(site.tsym, types)) { !sym.isInheritedIn(site.tsym, types)) {
return bestSoFar; return bestSoFar;
} else if (useVarargs && (sym.flags() & VARARGS) == 0) { } else if (useVarargs && (sym.flags() & VARARGS) == 0) {
return bestSoFar.kind.isOverloadError() ? return bestSoFar.kind.isResolutionError() ?
new BadVarargsMethod((ResolveError)bestSoFar.baseSymbol()) : new BadVarargsMethod((ResolveError)bestSoFar.baseSymbol()) :
bestSoFar; bestSoFar;
} }
Assert.check(!sym.kind.isOverloadError()); Assert.check(!sym.kind.isResolutionError());
try { try {
Type mt = rawInstantiate(env, site, sym, null, argtypes, typeargtypes, Type mt = rawInstantiate(env, site, sym, null, argtypes, typeargtypes,
allowBoxing, useVarargs, types.noWarnings); allowBoxing, useVarargs, types.noWarnings);
@ -1457,7 +1457,7 @@ public class Resolve {
? new AccessError(env, site, sym) ? new AccessError(env, site, sym)
: bestSoFar; : bestSoFar;
} }
return (bestSoFar.kind.isOverloadError() && bestSoFar.kind != AMBIGUOUS) return (bestSoFar.kind.isResolutionError() && bestSoFar.kind != AMBIGUOUS)
? sym ? sym
: mostSpecific(argtypes, sym, bestSoFar, env, site, useVarargs); : mostSpecific(argtypes, sym, bestSoFar, env, site, useVarargs);
} }
@ -1939,8 +1939,8 @@ public class Resolve {
bestSoFar.kind != AMBIGUOUS && l.nonEmpty(); bestSoFar.kind != AMBIGUOUS && l.nonEmpty();
l = l.tail) { l = l.tail) {
sym = findMemberType(env, site, name, l.head.tsym); sym = findMemberType(env, site, name, l.head.tsym);
if (!bestSoFar.kind.isOverloadError() && if (!bestSoFar.kind.isResolutionError() &&
!sym.kind.isOverloadError() && !sym.kind.isResolutionError() &&
sym.owner != bestSoFar.owner) sym.owner != bestSoFar.owner)
bestSoFar = new AmbiguityError(bestSoFar, sym); bestSoFar = new AmbiguityError(bestSoFar, sym);
else else
@ -2176,7 +2176,7 @@ public class Resolve {
List<Type> argtypes, List<Type> argtypes,
List<Type> typeargtypes, List<Type> typeargtypes,
LogResolveHelper logResolveHelper) { LogResolveHelper logResolveHelper) {
if (sym.kind.isOverloadError()) { if (sym.kind.isResolutionError()) {
ResolveError errSym = (ResolveError)sym.baseSymbol(); ResolveError errSym = (ResolveError)sym.baseSymbol();
sym = errSym.access(name, qualified ? site.tsym : syms.noSymbol); sym = errSym.access(name, qualified ? site.tsym : syms.noSymbol);
argtypes = logResolveHelper.getArgumentTypes(errSym, sym, name, argtypes); argtypes = logResolveHelper.getArgumentTypes(errSym, sym, name, argtypes);
@ -2366,7 +2366,7 @@ public class Resolve {
} }
@Override @Override
Symbol access(Env<AttrContext> env, DiagnosticPosition pos, Symbol location, Symbol sym) { Symbol access(Env<AttrContext> env, DiagnosticPosition pos, Symbol location, Symbol sym) {
if (sym.kind.isOverloadError()) { if (sym.kind.isResolutionError()) {
sym = super.access(env, pos, location, sym); sym = super.access(env, pos, location, sym);
} else if (allowMethodHandles) { } else if (allowMethodHandles) {
MethodSymbol msym = (MethodSymbol)sym; MethodSymbol msym = (MethodSymbol)sym;
@ -2523,7 +2523,7 @@ public class Resolve {
} }
@Override @Override
Symbol access(Env<AttrContext> env, DiagnosticPosition pos, Symbol location, Symbol sym) { Symbol access(Env<AttrContext> env, DiagnosticPosition pos, Symbol location, Symbol sym) {
if (sym.kind.isOverloadError()) { if (sym.kind.isResolutionError()) {
if (sym.kind != WRONG_MTH && if (sym.kind != WRONG_MTH &&
sym.kind != WRONG_MTHS) { sym.kind != WRONG_MTHS) {
sym = super.access(env, pos, location, sym); sym = super.access(env, pos, location, sym);
@ -2933,7 +2933,7 @@ public class Resolve {
*/ */
final boolean shouldStop(Symbol sym, MethodResolutionPhase phase) { final boolean shouldStop(Symbol sym, MethodResolutionPhase phase) {
return phase.ordinal() > maxPhase.ordinal() || return phase.ordinal() > maxPhase.ordinal() ||
!sym.kind.isOverloadError() || sym.kind == AMBIGUOUS; !sym.kind.isResolutionError() || sym.kind == AMBIGUOUS;
} }
/** /**
@ -2979,7 +2979,7 @@ public class Resolve {
@Override @Override
Symbol access(Env<AttrContext> env, DiagnosticPosition pos, Symbol location, Symbol sym) { Symbol access(Env<AttrContext> env, DiagnosticPosition pos, Symbol location, Symbol sym) {
if (sym.kind.isOverloadError()) { if (sym.kind.isResolutionError()) {
//if nothing is found return the 'first' error //if nothing is found return the 'first' error
sym = accessMethod(sym, pos, location, site, name, true, argtypes, typeargtypes); sym = accessMethod(sym, pos, location, site, name, true, argtypes, typeargtypes);
} }
@ -3321,7 +3321,7 @@ public class Resolve {
boolean hasEnclosingInstance(Env<AttrContext> env, Type type) { boolean hasEnclosingInstance(Env<AttrContext> env, Type type) {
Symbol encl = resolveSelfContainingInternal(env, type.tsym, false); Symbol encl = resolveSelfContainingInternal(env, type.tsym, false);
return encl != null && !encl.kind.isOverloadError(); return encl != null && !encl.kind.isResolutionError();
} }
private Symbol resolveSelfContainingInternal(Env<AttrContext> env, private Symbol resolveSelfContainingInternal(Env<AttrContext> env,
@ -3503,7 +3503,7 @@ public class Resolve {
@Override @Override
public Symbol access(Name name, TypeSymbol location) { public Symbol access(Name name, TypeSymbol location) {
if (!sym.kind.isOverloadError() && sym.kind.matches(KindSelector.TYP)) if (!sym.kind.isResolutionError() && sym.kind.matches(KindSelector.TYP))
return types.createErrorType(name, location, sym.type).tsym; return types.createErrorType(name, location, sym.type).tsym;
else else
return sym; return sym;
@ -4053,7 +4053,7 @@ public class Resolve {
} else { } else {
key = "bad.instance.method.in.unbound.lookup"; key = "bad.instance.method.in.unbound.lookup";
} }
return sym.kind.isOverloadError() ? return sym.kind.isResolutionError() ?
((ResolveError)sym).getDiagnostic(dkind, pos, location, site, name, argtypes, typeargtypes) : ((ResolveError)sym).getDiagnostic(dkind, pos, location, site, name, argtypes, typeargtypes) :
diags.create(dkind, log.currentSource(), pos, key, Kinds.kindName(sym), sym); diags.create(dkind, log.currentSource(), pos, key, Kinds.kindName(sym), sym);
} }
@ -4232,8 +4232,8 @@ public class Resolve {
@Override @Override
public Symbol mergeResults(Symbol bestSoFar, Symbol sym) { public Symbol mergeResults(Symbol bestSoFar, Symbol sym) {
//Check invariants (see {@code LookupHelper.shouldStop}) //Check invariants (see {@code LookupHelper.shouldStop})
Assert.check(bestSoFar.kind.isOverloadError() && bestSoFar.kind != AMBIGUOUS); Assert.check(bestSoFar.kind.isResolutionError() && bestSoFar.kind != AMBIGUOUS);
if (!sym.kind.isOverloadError()) { if (!sym.kind.isResolutionError()) {
//varargs resolution successful //varargs resolution successful
return sym; return sym;
} else { } else {

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -21,9 +21,8 @@
* questions. * questions.
*/ */
// key: compiler.err.prob.found.req
// key: compiler.misc.cant.access.inner.cls.constr // key: compiler.misc.cant.access.inner.cls.constr
// key: compiler.misc.invalid.mref // key: compiler.err.invalid.mref
class CantAccessInnerClsConstructor { class CantAccessInnerClsConstructor {

View File

@ -1,6 +1,6 @@
/* /*
* @test /nodynamiccopyright/ * @test /nodynamiccopyright/
* @bug 8003280 * @bug 8003280 8075184
* @summary Add lambda tests * @summary Add lambda tests
* check that pair of bound/non-bound constructor references is flagged as ambiguous * check that pair of bound/non-bound constructor references is flagged as ambiguous
* @author Maurizio Cimadamore * @author Maurizio Cimadamore

View File

@ -1,6 +1,6 @@
MethodReference23.java:52:19: compiler.err.prob.found.req: (compiler.misc.invalid.mref: kindname.constructor, (compiler.misc.cant.access.inner.cls.constr: Inner1, MethodReference23, MethodReference23)) MethodReference23.java:52:19: compiler.err.invalid.mref: kindname.constructor, (compiler.misc.cant.access.inner.cls.constr: Inner1, MethodReference23, MethodReference23)
MethodReference23.java:53:15: compiler.err.cant.apply.symbol: kindname.method, call11, MethodReference23.SAM11, @1140, kindname.class, MethodReference23, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.invalid.mref: kindname.constructor, (compiler.misc.cant.access.inner.cls.constr: Inner1, MethodReference23, MethodReference23))) MethodReference23.java:53:16: compiler.err.invalid.mref: kindname.constructor, (compiler.misc.cant.access.inner.cls.constr: Inner1, MethodReference23, MethodReference23)
MethodReference23.java:57:19: compiler.err.prob.found.req: (compiler.misc.invalid.mref: kindname.constructor, (compiler.misc.cant.access.inner.cls.constr: Inner1, , MethodReference23)) MethodReference23.java:57:19: compiler.err.invalid.mref: kindname.constructor, (compiler.misc.cant.access.inner.cls.constr: Inner1, , MethodReference23)
MethodReference23.java:58:15: compiler.err.cant.apply.symbol: kindname.method, call12, MethodReference23.SAM12, @1282, kindname.class, MethodReference23, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.invalid.mref: kindname.constructor, (compiler.misc.cant.access.inner.cls.constr: Inner1, , MethodReference23))) MethodReference23.java:58:16: compiler.err.invalid.mref: kindname.constructor, (compiler.misc.cant.access.inner.cls.constr: Inner1, , MethodReference23)
MethodReference23.java:72:9: compiler.err.ref.ambiguous: call3, kindname.method, call3(MethodReference23.SAM21), MethodReference23, kindname.method, call3(MethodReference23.SAM22), MethodReference23 MethodReference23.java:72:9: compiler.err.ref.ambiguous: call3, kindname.method, call3(MethodReference23.SAM21), MethodReference23, kindname.method, call3(MethodReference23.SAM22), MethodReference23
5 errors 5 errors