changeset 1598:9f0ec00514b6

8007461: Regression: bad overload resolution when inner class and outer class have method with same name Summary: Fix regression in varargs method resolution introduced by bad refactoring Reviewed-by: jjg
author mcimadamore
date Thu, 21 Feb 2013 15:26:46 +0000
parents 7ac9242d2ca6
children 3fef0cae83b3
files src/share/classes/com/sun/tools/javac/comp/Resolve.java test/tools/javac/resolve/Pos.java test/tools/javac/resolve/tests/InnerOverOuter.java
diffstat 3 files changed, 71 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/com/sun/tools/javac/comp/Resolve.java	Thu Feb 21 15:25:03 2013 +0000
+++ b/src/share/classes/com/sun/tools/javac/comp/Resolve.java	Thu Feb 21 15:26:46 2013 +0000
@@ -1244,9 +1244,12 @@
                       boolean useVarargs,
                       boolean operator) {
         if (sym.kind == ERR ||
-                !sym.isInheritedIn(site.tsym, types) ||
-                (useVarargs && (sym.flags() & VARARGS) == 0)) {
+                !sym.isInheritedIn(site.tsym, types)) {
             return bestSoFar;
+        } else if (useVarargs && (sym.flags() & VARARGS) == 0) {
+            return bestSoFar.kind >= ERRONEOUS ?
+                    new BadVarargsMethod((ResolveError)bestSoFar) :
+                    bestSoFar;
         }
         Assert.check(sym.kind < AMBIGUOUS);
         try {
@@ -3522,6 +3525,31 @@
         }
     }
 
+    class BadVarargsMethod extends ResolveError {
+
+        ResolveError delegatedError;
+
+        BadVarargsMethod(ResolveError delegatedError) {
+            super(delegatedError.kind, "badVarargs");
+            this.delegatedError = delegatedError;
+        }
+
+        @Override
+        protected Symbol access(Name name, TypeSymbol location) {
+            return delegatedError.access(name, location);
+        }
+
+        @Override
+        public boolean exists() {
+            return true;
+        }
+
+        @Override
+        JCDiagnostic getDiagnostic(DiagnosticType dkind, DiagnosticPosition pos, Symbol location, Type site, Name name, List<Type> argtypes, List<Type> typeargtypes) {
+            return delegatedError.getDiagnostic(dkind, pos, location, site, name, argtypes, typeargtypes);
+        }
+    }
+
     enum MethodResolutionPhase {
         BASIC(false, false),
         BOX(true, false),
--- a/test/tools/javac/resolve/Pos.java	Thu Feb 21 15:25:03 2013 +0000
+++ b/test/tools/javac/resolve/Pos.java	Thu Feb 21 15:26:46 2013 +0000
@@ -28,4 +28,4 @@
     long line() default -1;
     long col() default -1;
     boolean userDefined() default true;
-}
\ No newline at end of file
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/resolve/tests/InnerOverOuter.java	Thu Feb 21 15:26:46 2013 +0000
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2013, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+@TraceResolve
+class Test {
+
+    //no annotation here - this should NOT even be considered!
+    void m(Integer i1, Integer i2) { }
+
+    //no annotation here - this should NOT even be considered!
+    void m(Object... o) { }
+
+    @TraceResolve(keys={"compiler.err.cant.apply.symbol"})
+    class Inner {
+        @Candidate
+        void m(String s) {
+            m(1, 1); //should fail
+        }
+    }
+}