From 96a45dadf834739beb2093da44e222a998f828e1 Mon Sep 17 00:00:00 2001 From: mcimadamore Date: Wed, 19 May 2010 16:42:37 +0100 Subject: [PATCH] 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 --- .../com/sun/tools/javac/comp/Attr.java | 16 +++++++++----- .../javac/generics/6946618/T6946618a.java | 21 +++++++++++++++++++ .../javac/generics/6946618/T6946618a.out | 2 ++ .../javac/generics/6946618/T6946618b.java | 21 +++++++++++++++++++ .../javac/generics/6946618/T6946618b.out | 2 ++ .../javac/generics/6946618/T6946618c.java | 17 +++++++++++++++ .../javac/generics/6946618/T6946618c.out | 4 ++++ 7 files changed, 78 insertions(+), 5 deletions(-) create mode 100644 test/tools/javac/generics/6946618/T6946618a.java create mode 100644 test/tools/javac/generics/6946618/T6946618a.out create mode 100644 test/tools/javac/generics/6946618/T6946618b.java create mode 100644 test/tools/javac/generics/6946618/T6946618b.out create mode 100644 test/tools/javac/generics/6946618/T6946618c.java create mode 100644 test/tools/javac/generics/6946618/T6946618c.out diff --git a/src/share/classes/com/sun/tools/javac/comp/Attr.java b/src/share/classes/com/sun/tools/javac/comp/Attr.java index cf1cf2c7..3f776c51 100644 --- a/src/share/classes/com/sun/tools/javac/comp/Attr.java +++ b/src/share/classes/com/sun/tools/javac/comp/Attr.java @@ -1472,7 +1472,7 @@ public class Attr extends JCTree.Visitor { // 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 @@ public class Attr extends JCTree.Visitor { 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 @@ public class Attr extends JCTree.Visitor { * 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 @@ public class Attr extends JCTree.Visitor { return mapping; } + private final Pair erroneousMapping = new Pair(null, null); + /** Make an attributed null check tree. */ public JCExpression makeNullCheck(JCExpression arg) { diff --git a/test/tools/javac/generics/6946618/T6946618a.java b/test/tools/javac/generics/6946618/T6946618a.java new file mode 100644 index 00000000..7ddabc21 --- /dev/null +++ b/test/tools/javac/generics/6946618/T6946618a.java @@ -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 --git a/test/tools/javac/generics/6946618/T6946618a.out b/test/tools/javac/generics/6946618/T6946618a.out new file mode 100644 index 00000000..dfb46b49 --- /dev/null +++ b/test/tools/javac/generics/6946618/T6946618a.out @@ -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 --git a/test/tools/javac/generics/6946618/T6946618b.java b/test/tools/javac/generics/6946618/T6946618b.java new file mode 100644 index 00000000..af600a92 --- /dev/null +++ b/test/tools/javac/generics/6946618/T6946618b.java @@ -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 --git a/test/tools/javac/generics/6946618/T6946618b.out b/test/tools/javac/generics/6946618/T6946618b.out new file mode 100644 index 00000000..d5460848 --- /dev/null +++ b/test/tools/javac/generics/6946618/T6946618b.out @@ -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 --git a/test/tools/javac/generics/6946618/T6946618c.java b/test/tools/javac/generics/6946618/T6946618c.java new file mode 100644 index 00000000..034ecb5e --- /dev/null +++ b/test/tools/javac/generics/6946618/T6946618c.java @@ -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 --git a/test/tools/javac/generics/6946618/T6946618c.out b/test/tools/javac/generics/6946618/T6946618c.out new file mode 100644 index 00000000..01da79b2 --- /dev/null +++ b/test/tools/javac/generics/6946618/T6946618c.out @@ -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 -- GitLab