mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-19 10:34:38 +02:00
8296171: Compiler incorrectly rejects code with variadic method references
Reviewed-by: mcimadamore
This commit is contained in:
parent
749335d34a
commit
3eb789af74
2 changed files with 36 additions and 15 deletions
|
@ -3111,7 +3111,8 @@ public class Resolve {
|
|||
boundSearchResolveContext.methodCheck = methodCheck;
|
||||
Symbol boundSym = lookupMethod(boundEnv, env.tree.pos(),
|
||||
site.tsym, boundSearchResolveContext, boundLookupHelper);
|
||||
ReferenceLookupResult boundRes = new ReferenceLookupResult(boundSym, boundSearchResolveContext);
|
||||
boolean isStaticSelector = TreeInfo.isStaticSelector(referenceTree.expr, names);
|
||||
ReferenceLookupResult boundRes = new ReferenceLookupResult(boundSym, boundSearchResolveContext, isStaticSelector);
|
||||
if (dumpMethodReferenceSearchResults) {
|
||||
dumpMethodReferenceSearchResults(referenceTree, boundSearchResolveContext, boundSym, true);
|
||||
}
|
||||
|
@ -3127,7 +3128,7 @@ public class Resolve {
|
|||
unboundSearchResolveContext.methodCheck = methodCheck;
|
||||
unboundSym = lookupMethod(unboundEnv, env.tree.pos(),
|
||||
site.tsym, unboundSearchResolveContext, unboundLookupHelper);
|
||||
unboundRes = new ReferenceLookupResult(unboundSym, unboundSearchResolveContext);
|
||||
unboundRes = new ReferenceLookupResult(unboundSym, unboundSearchResolveContext, isStaticSelector);
|
||||
if (dumpMethodReferenceSearchResults) {
|
||||
dumpMethodReferenceSearchResults(referenceTree, unboundSearchResolveContext, unboundSym, false);
|
||||
}
|
||||
|
@ -3238,8 +3239,8 @@ public class Resolve {
|
|||
/** The lookup result. */
|
||||
Symbol sym;
|
||||
|
||||
ReferenceLookupResult(Symbol sym, MethodResolutionContext resolutionContext) {
|
||||
this(sym, staticKind(sym, resolutionContext));
|
||||
ReferenceLookupResult(Symbol sym, MethodResolutionContext resolutionContext, boolean isStaticSelector) {
|
||||
this(sym, staticKind(sym, resolutionContext, isStaticSelector));
|
||||
}
|
||||
|
||||
private ReferenceLookupResult(Symbol sym, StaticKind staticKind) {
|
||||
|
@ -3247,16 +3248,16 @@ public class Resolve {
|
|||
this.sym = sym;
|
||||
}
|
||||
|
||||
private static StaticKind staticKind(Symbol sym, MethodResolutionContext resolutionContext) {
|
||||
switch (sym.kind) {
|
||||
case MTH:
|
||||
case AMBIGUOUS:
|
||||
private static StaticKind staticKind(Symbol sym, MethodResolutionContext resolutionContext, boolean isStaticSelector) {
|
||||
if (sym.kind == MTH && !isStaticSelector) {
|
||||
return StaticKind.from(sym);
|
||||
} else if (sym.kind == MTH || sym.kind == AMBIGUOUS) {
|
||||
return resolutionContext.candidates.stream()
|
||||
.filter(c -> c.isApplicable() && c.step == resolutionContext.step)
|
||||
.map(c -> StaticKind.from(c.sym))
|
||||
.reduce(StaticKind::reduce)
|
||||
.orElse(StaticKind.UNDEFINED);
|
||||
default:
|
||||
} else {
|
||||
return StaticKind.UNDEFINED;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -132,5 +132,25 @@ public class BoundUnboundSearchTest extends CompilationTestCase {
|
|||
}
|
||||
"""
|
||||
);
|
||||
|
||||
assertOK(
|
||||
getDiagConsumer(0, -1),
|
||||
"""
|
||||
import java.util.function.*;
|
||||
|
||||
interface Intf {
|
||||
Object apply(String... args);
|
||||
}
|
||||
|
||||
public class Test {
|
||||
public static Object foo(Object o) { return "bar"; }
|
||||
public final Object foo(Object... o) { return "foo"; }
|
||||
|
||||
public void test() {
|
||||
Intf f = this::foo;
|
||||
}
|
||||
}
|
||||
"""
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue