Mercurial > hg > jdk9-shenandoah > langtools
changeset 2904:1f483cea54fb
8078592: Compiler fails to reject erroneous use of diamond with anonymous classes involving "fresh" type variables.
Reviewed-by: mcimadamore
author | sadayapalam |
---|---|
date | Sat, 25 Apr 2015 15:59:54 +0530 |
parents | a28b7f42dae9 |
children | 520635aae9e1 |
files | src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java test/tools/javac/generics/diamond/neg/Neg20.java test/tools/javac/generics/diamond/neg/Neg20.out |
diffstat | 3 files changed, 47 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java Thu Apr 30 17:35:03 2015 -0700 +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java Sat Apr 25 15:59:54 2015 +0530 @@ -841,6 +841,15 @@ } 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;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/generics/diamond/neg/Neg20.java Sat Apr 25 15:59:54 2015 +0530 @@ -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<>() { + }; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/generics/diamond/neg/Neg20.out Sat Apr 25 15:59:54 2015 +0530 @@ -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