8078592: Compiler fails to reject erroneous use of diamond with anonymous classes involving "fresh" type variables

Reviewed-by: mcimadamore
This commit is contained in:
Srikanth Adayapalam 2015-04-25 15:59:54 +05:30
parent cbb7a567ca
commit f2ee4e4240
3 changed files with 47 additions and 0 deletions

View File

@ -841,6 +841,15 @@ public class Check {
}
return true;
}
@Override
public Boolean visitTypeVar(TypeVar t, Void s) {
/* Any type variable mentioned in the inferred type must have been declared as a type parameter
(i.e cannot have been produced by capture conversion (5.1.10) or by inference (18.4)
*/
return t.tsym.owner.type.getTypeArguments().contains(t);
}
@Override
public Boolean visitCapturedType(CapturedType t, Void s) {
return false;

View File

@ -0,0 +1,36 @@
/*
* @test /nodynamiccopyright/
* @bug 8078592
* @summary Compiler fails to reject erroneous use of diamond with anonymous classes involving "fresh" type variables.
* @compile/fail/ref=Neg20.out Neg20.java -XDrawDiagnostics
*/
import java.lang.annotation.ElementType;
import java.lang.annotation.Target;
public class Neg20 {
static class Foo<E extends B<E>> {
public Foo<E> complexMethod(E a) {
return this;
}
}
static class Goo<@T E> {
public Goo<E> complexMethod(E a) {
return this;
}
}
static class B<V> {
}
@Target(ElementType.TYPE_USE)
static @interface T {
}
public static void check() {
Foo<?> t4 = new Foo<>() {
};
Goo<?> g4 = new Goo<>() {
};
}
}

View File

@ -0,0 +1,2 @@
Neg20.java:31:28: compiler.err.cant.apply.diamond.1: (compiler.misc.diamond: Neg20.Foo), (compiler.misc.diamond.invalid.arg: E, (compiler.misc.diamond: Neg20.Foo))
1 error