mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-19 18:44: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;
|
boundSearchResolveContext.methodCheck = methodCheck;
|
||||||
Symbol boundSym = lookupMethod(boundEnv, env.tree.pos(),
|
Symbol boundSym = lookupMethod(boundEnv, env.tree.pos(),
|
||||||
site.tsym, boundSearchResolveContext, boundLookupHelper);
|
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) {
|
if (dumpMethodReferenceSearchResults) {
|
||||||
dumpMethodReferenceSearchResults(referenceTree, boundSearchResolveContext, boundSym, true);
|
dumpMethodReferenceSearchResults(referenceTree, boundSearchResolveContext, boundSym, true);
|
||||||
}
|
}
|
||||||
|
@ -3127,7 +3128,7 @@ public class Resolve {
|
||||||
unboundSearchResolveContext.methodCheck = methodCheck;
|
unboundSearchResolveContext.methodCheck = methodCheck;
|
||||||
unboundSym = lookupMethod(unboundEnv, env.tree.pos(),
|
unboundSym = lookupMethod(unboundEnv, env.tree.pos(),
|
||||||
site.tsym, unboundSearchResolveContext, unboundLookupHelper);
|
site.tsym, unboundSearchResolveContext, unboundLookupHelper);
|
||||||
unboundRes = new ReferenceLookupResult(unboundSym, unboundSearchResolveContext);
|
unboundRes = new ReferenceLookupResult(unboundSym, unboundSearchResolveContext, isStaticSelector);
|
||||||
if (dumpMethodReferenceSearchResults) {
|
if (dumpMethodReferenceSearchResults) {
|
||||||
dumpMethodReferenceSearchResults(referenceTree, unboundSearchResolveContext, unboundSym, false);
|
dumpMethodReferenceSearchResults(referenceTree, unboundSearchResolveContext, unboundSym, false);
|
||||||
}
|
}
|
||||||
|
@ -3238,8 +3239,8 @@ public class Resolve {
|
||||||
/** The lookup result. */
|
/** The lookup result. */
|
||||||
Symbol sym;
|
Symbol sym;
|
||||||
|
|
||||||
ReferenceLookupResult(Symbol sym, MethodResolutionContext resolutionContext) {
|
ReferenceLookupResult(Symbol sym, MethodResolutionContext resolutionContext, boolean isStaticSelector) {
|
||||||
this(sym, staticKind(sym, resolutionContext));
|
this(sym, staticKind(sym, resolutionContext, isStaticSelector));
|
||||||
}
|
}
|
||||||
|
|
||||||
private ReferenceLookupResult(Symbol sym, StaticKind staticKind) {
|
private ReferenceLookupResult(Symbol sym, StaticKind staticKind) {
|
||||||
|
@ -3247,16 +3248,16 @@ public class Resolve {
|
||||||
this.sym = sym;
|
this.sym = sym;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static StaticKind staticKind(Symbol sym, MethodResolutionContext resolutionContext) {
|
private static StaticKind staticKind(Symbol sym, MethodResolutionContext resolutionContext, boolean isStaticSelector) {
|
||||||
switch (sym.kind) {
|
if (sym.kind == MTH && !isStaticSelector) {
|
||||||
case MTH:
|
return StaticKind.from(sym);
|
||||||
case AMBIGUOUS:
|
} else if (sym.kind == MTH || sym.kind == AMBIGUOUS) {
|
||||||
return resolutionContext.candidates.stream()
|
return resolutionContext.candidates.stream()
|
||||||
.filter(c -> c.isApplicable() && c.step == resolutionContext.step)
|
.filter(c -> c.isApplicable() && c.step == resolutionContext.step)
|
||||||
.map(c -> StaticKind.from(c.sym))
|
.map(c -> StaticKind.from(c.sym))
|
||||||
.reduce(StaticKind::reduce)
|
.reduce(StaticKind::reduce)
|
||||||
.orElse(StaticKind.UNDEFINED);
|
.orElse(StaticKind.UNDEFINED);
|
||||||
default:
|
} else {
|
||||||
return StaticKind.UNDEFINED;
|
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