8185451: Misleading 'cannot be accessed from outside package' diagnostic for inconsistent varargs override
authorvromero
Mon, 27 Nov 2017 13:26:31 -0500
changeset 47942 06652ffab955
parent 47941 d91b0d2d45cb
child 47943 cece8b7adf10
child 47976 7bcdb571ae31
child 55894 6da4c12646f3
8185451: Misleading 'cannot be accessed from outside package' diagnostic for inconsistent varargs override Reviewed-by: mcimadamore
src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Resolve.java
test/langtools/tools/javac/T8185451/MisleadingVarArgsErrorMsgTest.java
test/langtools/tools/javac/T8185451/MisleadingVarArgsErrorMsgTest.out
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Resolve.java	Mon Nov 27 19:16:55 2017 +0100
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Resolve.java	Mon Nov 27 13:26:31 2017 -0500
@@ -1548,7 +1548,8 @@
                       boolean allowBoxing,
                       boolean useVarargs) {
         if (sym.kind == ERR ||
-                !sym.isInheritedIn(site.tsym, types)) {
+                (site.tsym != sym.owner && !sym.isInheritedIn(site.tsym, types)) ||
+                !notOverriddenIn(site, sym)) {
             return bestSoFar;
         } else if (useVarargs && (sym.flags() & VARARGS) == 0) {
             return bestSoFar.kind.isResolutionError() ?
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/langtools/tools/javac/T8185451/MisleadingVarArgsErrorMsgTest.java	Mon Nov 27 13:26:31 2017 -0500
@@ -0,0 +1,21 @@
+/*
+ * @test  /nodynamiccopyright/
+ * @bug 8185451
+ * @summary Misleading 'cannot be accessed from outside package' diagnostic for inconsistent varargs override
+ * @compile/fail/ref=MisleadingVarArgsErrorMsgTest.out -XDrawDiagnostics MisleadingVarArgsErrorMsgTest.java
+ */
+
+class MisleadingVarArgsErrorMsgTest {
+    class A {
+        void f(int... x) {}
+    }
+
+    class B extends A {
+        @Override
+        void f(int[] x) {}
+    }
+
+    {
+        new B().f(1);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/langtools/tools/javac/T8185451/MisleadingVarArgsErrorMsgTest.out	Mon Nov 27 13:26:31 2017 -0500
@@ -0,0 +1,2 @@
+MisleadingVarArgsErrorMsgTest.java:19:16: compiler.err.cant.apply.symbol: kindname.method, f, int[], int, kindname.class, MisleadingVarArgsErrorMsgTest.B, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.inconvertible.types: int, int[]))
+1 error