8205052: No compilation error thrown when no valid parameterization exists for functional interface type
Reviewed-by: mcimadamore
This commit is contained in:
parent
ebe240f3f4
commit
58f944b75e
@ -676,10 +676,21 @@ public class Types {
|
||||
|
||||
public Type getType(Type site) {
|
||||
site = removeWildcards(site);
|
||||
if (!chk.checkValidGenericType(site)) {
|
||||
//if the inferred functional interface type is not well-formed,
|
||||
//or if it's not a subtype of the original target, issue an error
|
||||
throw failure(diags.fragment(Fragments.NoSuitableFunctionalIntfInst(site)));
|
||||
if (site.isIntersection()) {
|
||||
IntersectionClassType ict = (IntersectionClassType)site;
|
||||
for (Type component : ict.getExplicitComponents()) {
|
||||
if (!chk.checkValidGenericType(component)) {
|
||||
//if the inferred functional interface type is not well-formed,
|
||||
//or if it's not a subtype of the original target, issue an error
|
||||
throw failure(diags.fragment(Fragments.NoSuitableFunctionalIntfInst(site)));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (!chk.checkValidGenericType(site)) {
|
||||
//if the inferred functional interface type is not well-formed,
|
||||
//or if it's not a subtype of the original target, issue an error
|
||||
throw failure(diags.fragment(Fragments.NoSuitableFunctionalIntfInst(site)));
|
||||
}
|
||||
}
|
||||
return memberType(site, descSym);
|
||||
}
|
||||
|
@ -0,0 +1,32 @@
|
||||
/*
|
||||
* @test /nodynamiccopyright/
|
||||
* @bug 8203338
|
||||
* @summary Unboxing in return from lambda miscompiled to throw ClassCastException
|
||||
* @compile/fail/ref=CheckWellFormednessIntersectionTypesTest.out -XDrawDiagnostics CheckWellFormednessIntersectionTypesTest.java
|
||||
*/
|
||||
|
||||
public class CheckWellFormednessIntersectionTypesTest {
|
||||
class U1 {}
|
||||
class U3 {}
|
||||
|
||||
class X1 extends U1 {}
|
||||
class X3 extends U3 {}
|
||||
|
||||
interface SAM<P1 extends X1, P2 extends P1, P3 extends X3> {
|
||||
P3 m(P1 p1, P2 p2);
|
||||
}
|
||||
|
||||
interface I<T> {}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
class Tester {
|
||||
public X3 foo(X1 x1, Object x2) { return new X3(); }
|
||||
Object method(SAM<?, ?, ?> sam) {
|
||||
return sam.m(null, null);
|
||||
}
|
||||
|
||||
Object foo() {
|
||||
return method((SAM<?, ?, ?> & I<?>) this::foo);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,2 @@
|
||||
CheckWellFormednessIntersectionTypesTest.java:29:49: compiler.err.prob.found.req: (compiler.misc.no.suitable.functional.intf.inst: java.lang.Object&CheckWellFormednessIntersectionTypesTest.SAM<CheckWellFormednessIntersectionTypesTest.X1,java.lang.Object,CheckWellFormednessIntersectionTypesTest.X3>&CheckWellFormednessIntersectionTypesTest.I<java.lang.Object>)
|
||||
1 error
|
Loading…
x
Reference in New Issue
Block a user