# HG changeset patch # User mcimadamore # Date 1274283757 -3600 # Node ID c9e7ce44b1733339209d96a7ba368abf52054f08 # Parent e8aa492874b55d5b0f9145a4b4cd54a78ae761f1 6946618: sqe test fails: javac/generics/NewOnTypeParm in pit jdk7 b91 in all platforms. Summary: Bad cast to ClassType in the new diamond implementation fails if the target type of the instance creation expression is a type-variable Reviewed-by: jjg diff -r e8aa492874b5 -r c9e7ce44b173 langtools/src/share/classes/com/sun/tools/javac/comp/Attr.java --- a/langtools/src/share/classes/com/sun/tools/javac/comp/Attr.java Wed May 19 16:41:57 2010 +0100 +++ b/langtools/src/share/classes/com/sun/tools/javac/comp/Attr.java Wed May 19 16:42:37 2010 +0100 @@ -1472,7 +1472,7 @@ // Attribute clazz expression and store // symbol + type back into the attributed tree. Type clazztype = attribType(clazz, env); - Pair mapping = getSyntheticScopeMapping((ClassType)clazztype); + Pair mapping = getSyntheticScopeMapping(clazztype); if (!TreeInfo.isDiamond(tree)) { clazztype = chk.checkClassType( tree.clazz.pos(), clazztype, true); @@ -1640,9 +1640,10 @@ List argtypes, List typeargtypes, boolean reportErrors) { - if (clazztype.isErroneous()) { - //if the type of the instance creation expression is erroneous - //return the erroneous type itself + if (clazztype.isErroneous() || mapping == erroneousMapping) { + //if the type of the instance creation expression is erroneous, + //or something prevented us to form a valid mapping, return the + //(possibly erroneous) type unchanged return clazztype; } else if (clazztype.isInterface()) { @@ -1740,7 +1741,10 @@ * inference. The inferred return type of the synthetic constructor IS * the inferred type for the diamond operator. */ - private Pair getSyntheticScopeMapping(ClassType ctype) { + private Pair getSyntheticScopeMapping(Type ctype) { + if (ctype.tag != CLASS) { + return erroneousMapping; + } Pair mapping = new Pair(ctype.tsym.members(), new Scope(ctype.tsym)); List typevars = ctype.tsym.type.getTypeArguments(); @@ -1763,6 +1767,8 @@ return mapping; } + private final Pair erroneousMapping = new Pair(null, null); + /** Make an attributed null check tree. */ public JCExpression makeNullCheck(JCExpression arg) { diff -r e8aa492874b5 -r c9e7ce44b173 langtools/test/tools/javac/generics/6946618/T6946618a.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/generics/6946618/T6946618a.java Wed May 19 16:42:37 2010 +0100 @@ -0,0 +1,21 @@ +/* + * @test /nodynamiccopyright/ + * @bug 6946618 + * @summary sqe test fails: javac/generics/NewOnTypeParm in pit jdk7 b91 in all platforms. + * @author mcimadamore + * @compile/fail/ref=T6946618a.out -XDrawDiagnostics T6946618a.java + */ + +class T6946618a { + static class C { + T makeT() { + return new T(); //error + } + } + + static class D { + C makeC() { + return new C(); //ok + } + } +} diff -r e8aa492874b5 -r c9e7ce44b173 langtools/test/tools/javac/generics/6946618/T6946618a.out --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/generics/6946618/T6946618a.out Wed May 19 16:42:37 2010 +0100 @@ -0,0 +1,2 @@ +T6946618a.java:12:20: compiler.err.type.found.req: (compiler.misc.type.parameter: T), (compiler.misc.type.req.class) +1 error diff -r e8aa492874b5 -r c9e7ce44b173 langtools/test/tools/javac/generics/6946618/T6946618b.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/generics/6946618/T6946618b.java Wed May 19 16:42:37 2010 +0100 @@ -0,0 +1,21 @@ +/* + * @test /nodynamiccopyright/ + * @bug 6946618 + * @summary sqe test fails: javac/generics/NewOnTypeParm in pit jdk7 b91 in all platforms. + * @author mcimadamore + * @compile/fail/ref=T6946618b.out -XDrawDiagnostics T6946618b.java + */ + +class T6946618b { + static class C { + T makeT() { + return new T<>(); //error + } + } + + static class D { + C makeC() { + return new C<>(); //ok + } + } +} diff -r e8aa492874b5 -r c9e7ce44b173 langtools/test/tools/javac/generics/6946618/T6946618b.out --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/generics/6946618/T6946618b.out Wed May 19 16:42:37 2010 +0100 @@ -0,0 +1,2 @@ +T6946618b.java:12:20: compiler.err.type.found.req: (compiler.misc.type.parameter: T), (compiler.misc.type.req.class) +1 error diff -r e8aa492874b5 -r c9e7ce44b173 langtools/test/tools/javac/generics/6946618/T6946618c.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/generics/6946618/T6946618c.java Wed May 19 16:42:37 2010 +0100 @@ -0,0 +1,17 @@ +/* + * @test /nodynamiccopyright/ + * @bug 6946618 + * @summary sqe test fails: javac/generics/NewOnTypeParm in pit jdk7 b91 in all platforms. + * @author mcimadamore + * @compile/fail/ref=T6946618c.out -XDrawDiagnostics T6946618c.java + */ + +class T6946618c { + static class C { } + + void test() { + C c1 = new C(); + C c2 = new C(); + C c3 = new C(); + } +} diff -r e8aa492874b5 -r c9e7ce44b173 langtools/test/tools/javac/generics/6946618/T6946618c.out --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/generics/6946618/T6946618c.out Wed May 19 16:42:37 2010 +0100 @@ -0,0 +1,4 @@ +T6946618c.java:13:24: compiler.err.type.found.req: ? extends java.lang.String, class or interface without bounds +T6946618c.java:14:24: compiler.err.type.found.req: ? super java.lang.String, class or interface without bounds +T6946618c.java:15:24: compiler.err.type.found.req: ?, class or interface without bounds +3 errors