Thu, 21 Feb 2013 15:26:46 +0000
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
1.1 --- a/src/share/classes/com/sun/tools/javac/comp/Resolve.java Thu Feb 21 15:25:03 2013 +0000 1.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Resolve.java Thu Feb 21 15:26:46 2013 +0000 1.3 @@ -1244,9 +1244,12 @@ 1.4 boolean useVarargs, 1.5 boolean operator) { 1.6 if (sym.kind == ERR || 1.7 - !sym.isInheritedIn(site.tsym, types) || 1.8 - (useVarargs && (sym.flags() & VARARGS) == 0)) { 1.9 + !sym.isInheritedIn(site.tsym, types)) { 1.10 return bestSoFar; 1.11 + } else if (useVarargs && (sym.flags() & VARARGS) == 0) { 1.12 + return bestSoFar.kind >= ERRONEOUS ? 1.13 + new BadVarargsMethod((ResolveError)bestSoFar) : 1.14 + bestSoFar; 1.15 } 1.16 Assert.check(sym.kind < AMBIGUOUS); 1.17 try { 1.18 @@ -3522,6 +3525,31 @@ 1.19 } 1.20 } 1.21 1.22 + class BadVarargsMethod extends ResolveError { 1.23 + 1.24 + ResolveError delegatedError; 1.25 + 1.26 + BadVarargsMethod(ResolveError delegatedError) { 1.27 + super(delegatedError.kind, "badVarargs"); 1.28 + this.delegatedError = delegatedError; 1.29 + } 1.30 + 1.31 + @Override 1.32 + protected Symbol access(Name name, TypeSymbol location) { 1.33 + return delegatedError.access(name, location); 1.34 + } 1.35 + 1.36 + @Override 1.37 + public boolean exists() { 1.38 + return true; 1.39 + } 1.40 + 1.41 + @Override 1.42 + JCDiagnostic getDiagnostic(DiagnosticType dkind, DiagnosticPosition pos, Symbol location, Type site, Name name, List<Type> argtypes, List<Type> typeargtypes) { 1.43 + return delegatedError.getDiagnostic(dkind, pos, location, site, name, argtypes, typeargtypes); 1.44 + } 1.45 + } 1.46 + 1.47 enum MethodResolutionPhase { 1.48 BASIC(false, false), 1.49 BOX(true, false),
2.1 --- a/test/tools/javac/resolve/Pos.java Thu Feb 21 15:25:03 2013 +0000 2.2 +++ b/test/tools/javac/resolve/Pos.java Thu Feb 21 15:26:46 2013 +0000 2.3 @@ -28,4 +28,4 @@ 2.4 long line() default -1; 2.5 long col() default -1; 2.6 boolean userDefined() default true; 2.7 -} 2.8 \ No newline at end of file 2.9 +}
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 3.2 +++ b/test/tools/javac/resolve/tests/InnerOverOuter.java Thu Feb 21 15:26:46 2013 +0000 3.3 @@ -0,0 +1,40 @@ 3.4 +/* 3.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 3.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3.7 + * 3.8 + * This code is free software; you can redistribute it and/or modify it 3.9 + * under the terms of the GNU General Public License version 2 only, as 3.10 + * published by the Free Software Foundation. 3.11 + * 3.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 3.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 3.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 3.15 + * version 2 for more details (a copy is included in the LICENSE file that 3.16 + * accompanied this code). 3.17 + * 3.18 + * You should have received a copy of the GNU General Public License version 3.19 + * 2 along with this work; if not, write to the Free Software Foundation, 3.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 3.21 + * 3.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 3.23 + * or visit www.oracle.com if you need additional information or have any 3.24 + * questions. 3.25 + */ 3.26 + 3.27 +@TraceResolve 3.28 +class Test { 3.29 + 3.30 + //no annotation here - this should NOT even be considered! 3.31 + void m(Integer i1, Integer i2) { } 3.32 + 3.33 + //no annotation here - this should NOT even be considered! 3.34 + void m(Object... o) { } 3.35 + 3.36 + @TraceResolve(keys={"compiler.err.cant.apply.symbol"}) 3.37 + class Inner { 3.38 + @Candidate 3.39 + void m(String s) { 3.40 + m(1, 1); //should fail 3.41 + } 3.42 + } 3.43 +}