changeset 48139:06652ffab955

8185451: Misleading 'cannot be accessed from outside package' diagnostic for inconsistent varargs override Reviewed-by: mcimadamore
author vromero
date Mon, 27 Nov 2017 13:26:31 -0500
parents d91b0d2d45cb
children cece8b7adf10 7bcdb571ae31
files 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
diffstat 3 files changed, 25 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- 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