8075184: javac is mistakenly considering an missing enclosing instance error as an overload error
authorvromero
Fri, 27 Mar 2015 10:11:21 -0700
changeset 29774 9d438163db79
parent 29773 94a31accae17
child 29775 dc7df633fea1
8075184: javac is mistakenly considering an missing enclosing instance error as an overload error Reviewed-by: mcimadamore
langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Kinds.java
langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java
langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/DeferredAttr.java
langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Resolve.java
langtools/test/tools/javac/diags/examples/CantAccessInnerClsConstr.java
langtools/test/tools/javac/lambda/MethodReference23.java
langtools/test/tools/javac/lambda/MethodReference23.out
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Kinds.java	Thu Mar 26 16:17:36 2015 +0100
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Kinds.java	Fri Mar 27 10:11:21 2015 -0700
@@ -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.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -66,22 +66,22 @@
         MTH(Category.BASIC, KindName.METHOD, KindSelector.MTH),
         POLY(Category.BASIC, KindSelector.POLY),
         ERR(Category.ERROR, KindSelector.ERR),
-        AMBIGUOUS(Category.OVERLOAD),
-        HIDDEN(Category.OVERLOAD),
-        STATICERR(Category.OVERLOAD),
-        MISSING_ENCL(Category.OVERLOAD),
-        ABSENT_VAR(Category.OVERLOAD, KindName.VAR),
-        WRONG_MTHS(Category.OVERLOAD, KindName.METHOD),
-        WRONG_MTH(Category.OVERLOAD, KindName.METHOD),
-        ABSENT_MTH(Category.OVERLOAD, KindName.METHOD),
-        ABSENT_TYP(Category.OVERLOAD, KindName.CLASS);
+        AMBIGUOUS(Category.RESOLUTION_TARGET),                         // overloaded       target
+        HIDDEN(Category.RESOLUTION_TARGET),                            // not overloaded   non-target
+        STATICERR(Category.RESOLUTION_TARGET),                         // overloaded?      target
+        MISSING_ENCL(Category.RESOLUTION),                             // not overloaded   non-target
+        ABSENT_VAR(Category.RESOLUTION_TARGET, KindName.VAR),          // not overloaded   non-target
+        WRONG_MTHS(Category.RESOLUTION_TARGET, KindName.METHOD),       // overloaded       target
+        WRONG_MTH(Category.RESOLUTION_TARGET, KindName.METHOD),        // not overloaded   target
+        ABSENT_MTH(Category.RESOLUTION_TARGET, KindName.METHOD),       // not overloaded   non-target
+        ABSENT_TYP(Category.RESOLUTION_TARGET, KindName.CLASS);        // not overloaded   non-target
 
         // There are essentially two "levels" to the Kind datatype.
         // The first is a totally-ordered set of categories of
         // solutions.  Within each category, we have more
         // possibilities.
         private enum Category {
-            BASIC, ERROR, OVERLOAD;
+            BASIC, ERROR, RESOLUTION, RESOLUTION_TARGET;
         }
 
         private final KindName kindName;
@@ -127,8 +127,12 @@
             return selector.contains(kindSelectors);
         }
 
-        public boolean isOverloadError() {
-            return category == Category.OVERLOAD;
+        public boolean isResolutionError() {
+            return category == Category.RESOLUTION || category == Category.RESOLUTION_TARGET;
+        }
+
+        public boolean isResolutionTargetError() {
+            return category == Category.RESOLUTION_TARGET;
         }
 
         public boolean isValid() {
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java	Thu Mar 26 16:17:36 2015 +0100
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java	Fri Mar 27 10:11:21 2015 -0700
@@ -2109,7 +2109,7 @@
                 clazztype = cdef.sym.type;
                 Symbol sym = tree.constructor = rs.resolveConstructor(
                     tree.pos(), localEnv, clazztype, argtypes, typeargtypes);
-                Assert.check(!sym.kind.isOverloadError());
+                Assert.check(!sym.kind.isResolutionError());
                 tree.constructor = sym;
                 tree.constructorType = checkId(noCheckTree,
                     clazztype,
@@ -2647,17 +2647,20 @@
             Symbol refSym = refResult.fst;
             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) {
                 boolean targetError;
                 switch (refSym.kind) {
                     case ABSENT_MTH:
+                    case MISSING_ENCL:
                         targetError = false;
                         break;
                     case WRONG_MTH:
                     case WRONG_MTHS:
                     case AMBIGUOUS:
                     case HIDDEN:
-                    case MISSING_ENCL:
                     case STATICERR:
                         targetError = true;
                         break;
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/DeferredAttr.java	Thu Mar 26 16:17:36 2015 +0100
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/DeferredAttr.java	Fri Mar 27 10:11:21 2015 -0700
@@ -1209,8 +1209,8 @@
                     rs.getMemberReference(tree, localEnv, mref2,
                         exprTree.type, tree.name);
             tree.sym = res;
-            if (res.kind.isOverloadError() ||
-                    res.type.hasTag(FORALL) ||
+            if (res.kind.isResolutionTargetError() ||
+                    res.type != null && res.type.hasTag(FORALL) ||
                     (res.flags() & Flags.VARARGS) != 0 ||
                     (TreeInfo.isStaticSelector(exprTree, tree.name.table.names) &&
                     exprTree.type.isRaw())) {
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Resolve.java	Thu Mar 26 16:17:36 2015 +0100
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Resolve.java	Fri Mar 27 10:11:21 2015 -0700
@@ -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.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -194,7 +194,7 @@
 
     void reportVerboseResolutionDiagnostic(DiagnosticPosition dpos, Name name, Type site,
             List<Type> argtypes, List<Type> typeargtypes, Symbol bestSoFar) {
-        boolean success = !bestSoFar.kind.isOverloadError();
+        boolean success = !bestSoFar.kind.isResolutionError();
 
         if (success && !verboseResolutionMode.contains(VerboseResolutionMode.SUCCESS)) {
             return;
@@ -1389,7 +1389,7 @@
                 if (currentSymbol.kind != VAR)
                     continue;
                 // invariant: sym.kind == Symbol.Kind.VAR
-                if (!bestSoFar.kind.isOverloadError() &&
+                if (!bestSoFar.kind.isResolutionError() &&
                     currentSymbol.owner != bestSoFar.owner)
                     return new AmbiguityError(bestSoFar, currentSymbol);
                 else if (!bestSoFar.kind.betterThan(VAR)) {
@@ -1432,11 +1432,11 @@
                 !sym.isInheritedIn(site.tsym, types)) {
             return bestSoFar;
         } else if (useVarargs && (sym.flags() & VARARGS) == 0) {
-            return bestSoFar.kind.isOverloadError() ?
+            return bestSoFar.kind.isResolutionError() ?
                     new BadVarargsMethod((ResolveError)bestSoFar.baseSymbol()) :
                     bestSoFar;
         }
-        Assert.check(!sym.kind.isOverloadError());
+        Assert.check(!sym.kind.isResolutionError());
         try {
             Type mt = rawInstantiate(env, site, sym, null, argtypes, typeargtypes,
                                allowBoxing, useVarargs, types.noWarnings);
@@ -1457,7 +1457,7 @@
                 ? new AccessError(env, site, sym)
                 : bestSoFar;
         }
-        return (bestSoFar.kind.isOverloadError() && bestSoFar.kind != AMBIGUOUS)
+        return (bestSoFar.kind.isResolutionError() && bestSoFar.kind != AMBIGUOUS)
             ? sym
             : mostSpecific(argtypes, sym, bestSoFar, env, site, useVarargs);
     }
@@ -1939,8 +1939,8 @@
              bestSoFar.kind != AMBIGUOUS && l.nonEmpty();
              l = l.tail) {
             sym = findMemberType(env, site, name, l.head.tsym);
-            if (!bestSoFar.kind.isOverloadError() &&
-                !sym.kind.isOverloadError() &&
+            if (!bestSoFar.kind.isResolutionError() &&
+                !sym.kind.isResolutionError() &&
                 sym.owner != bestSoFar.owner)
                 bestSoFar = new AmbiguityError(bestSoFar, sym);
             else
@@ -2176,7 +2176,7 @@
                   List<Type> argtypes,
                   List<Type> typeargtypes,
                   LogResolveHelper logResolveHelper) {
-        if (sym.kind.isOverloadError()) {
+        if (sym.kind.isResolutionError()) {
             ResolveError errSym = (ResolveError)sym.baseSymbol();
             sym = errSym.access(name, qualified ? site.tsym : syms.noSymbol);
             argtypes = logResolveHelper.getArgumentTypes(errSym, sym, name, argtypes);
@@ -2366,7 +2366,7 @@
             }
             @Override
             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);
                 } else if (allowMethodHandles) {
                     MethodSymbol msym = (MethodSymbol)sym;
@@ -2523,7 +2523,7 @@
                     }
                     @Override
                     Symbol access(Env<AttrContext> env, DiagnosticPosition pos, Symbol location, Symbol sym) {
-                        if (sym.kind.isOverloadError()) {
+                        if (sym.kind.isResolutionError()) {
                             if (sym.kind != WRONG_MTH &&
                                 sym.kind != WRONG_MTHS) {
                                 sym = super.access(env, pos, location, sym);
@@ -2933,7 +2933,7 @@
          */
         final boolean shouldStop(Symbol sym, MethodResolutionPhase phase) {
             return phase.ordinal() > maxPhase.ordinal() ||
-                !sym.kind.isOverloadError() || sym.kind == AMBIGUOUS;
+                !sym.kind.isResolutionError() || sym.kind == AMBIGUOUS;
         }
 
         /**
@@ -2979,7 +2979,7 @@
 
         @Override
         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
                 sym = accessMethod(sym, pos, location, site, name, true, argtypes, typeargtypes);
             }
@@ -3321,7 +3321,7 @@
 
     boolean hasEnclosingInstance(Env<AttrContext> env, Type type) {
         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,
@@ -3503,7 +3503,7 @@
 
         @Override
         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;
             else
                 return sym;
@@ -4053,7 +4053,7 @@
             } else {
                 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) :
                     diags.create(dkind, log.currentSource(), pos, key, Kinds.kindName(sym), sym);
         }
@@ -4232,8 +4232,8 @@
             @Override
             public Symbol mergeResults(Symbol bestSoFar, Symbol sym) {
                 //Check invariants (see {@code LookupHelper.shouldStop})
-                Assert.check(bestSoFar.kind.isOverloadError() && bestSoFar.kind != AMBIGUOUS);
-                if (!sym.kind.isOverloadError()) {
+                Assert.check(bestSoFar.kind.isResolutionError() && bestSoFar.kind != AMBIGUOUS);
+                if (!sym.kind.isResolutionError()) {
                     //varargs resolution successful
                     return sym;
                 } else {
--- a/langtools/test/tools/javac/diags/examples/CantAccessInnerClsConstr.java	Thu Mar 26 16:17:36 2015 +0100
+++ b/langtools/test/tools/javac/diags/examples/CantAccessInnerClsConstr.java	Fri Mar 27 10:11:21 2015 -0700
@@ -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.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -21,9 +21,8 @@
  * questions.
  */
 
-// key: compiler.err.prob.found.req
 // key: compiler.misc.cant.access.inner.cls.constr
-// key: compiler.misc.invalid.mref
+// key: compiler.err.invalid.mref
 
 class CantAccessInnerClsConstructor {
 
--- a/langtools/test/tools/javac/lambda/MethodReference23.java	Thu Mar 26 16:17:36 2015 +0100
+++ b/langtools/test/tools/javac/lambda/MethodReference23.java	Fri Mar 27 10:11:21 2015 -0700
@@ -1,6 +1,6 @@
 /*
  * @test /nodynamiccopyright/
- * @bug 8003280
+ * @bug 8003280 8075184
  * @summary Add lambda tests
  *  check that pair of bound/non-bound constructor references is flagged as ambiguous
  * @author  Maurizio Cimadamore
--- a/langtools/test/tools/javac/lambda/MethodReference23.out	Thu Mar 26 16:17:36 2015 +0100
+++ b/langtools/test/tools/javac/lambda/MethodReference23.out	Fri Mar 27 10:11:21 2015 -0700
@@ -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: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:57:19: compiler.err.prob.found.req: (compiler.misc.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:52:19: compiler.err.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.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
 5 errors