8007461: Regression: bad overload resolution when inner class and outer class have method with same name

Fix regression in varargs method resolution introduced by bad refactoring

Reviewed-by: jjg
This commit is contained in:
Maurizio Cimadamore 2013-02-21 15:26:46 +00:00
parent 8c1621ee38
commit 6fd868a306
3 changed files with 71 additions and 3 deletions

View file

@ -1244,9 +1244,12 @@ public class Resolve {
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 @@ public class Resolve {
}
}
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),

View file

@ -28,4 +28,4 @@ import java.lang.annotation.Target;
long line() default -1;
long col() default -1;
boolean userDefined() default true;
}
}

View file

@ -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
}
}
}