changeset 561:2881b376a689

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
author mcimadamore
date Wed, 19 May 2010 16:42:37 +0100
parents e9ef849ae0ed
children eb849389ae2c
files src/share/classes/com/sun/tools/javac/comp/Attr.java test/tools/javac/generics/6946618/T6946618a.java test/tools/javac/generics/6946618/T6946618a.out test/tools/javac/generics/6946618/T6946618b.java test/tools/javac/generics/6946618/T6946618b.out test/tools/javac/generics/6946618/T6946618c.java test/tools/javac/generics/6946618/T6946618c.out
diffstat 7 files changed, 78 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/com/sun/tools/javac/comp/Attr.java	Wed May 19 16:41:57 2010 +0100
+++ b/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<Scope,Scope> mapping = getSyntheticScopeMapping((ClassType)clazztype);
+        Pair<Scope,Scope> mapping = getSyntheticScopeMapping(clazztype);
         if (!TreeInfo.isDiamond(tree)) {
             clazztype = chk.checkClassType(
                 tree.clazz.pos(), clazztype, true);
@@ -1640,9 +1640,10 @@
                         List<Type> argtypes,
                         List<Type> 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<Scope, Scope> getSyntheticScopeMapping(ClassType ctype) {
+    private Pair<Scope, Scope> getSyntheticScopeMapping(Type ctype) {
+        if (ctype.tag != CLASS) {
+            return erroneousMapping;
+        }
         Pair<Scope, Scope> mapping =
                 new Pair<Scope, Scope>(ctype.tsym.members(), new Scope(ctype.tsym));
         List<Type> typevars = ctype.tsym.type.getTypeArguments();
@@ -1763,6 +1767,8 @@
         return mapping;
     }
 
+    private final Pair<Scope,Scope> erroneousMapping = new Pair<Scope,Scope>(null, null);
+
     /** Make an attributed null check tree.
      */
     public JCExpression makeNullCheck(JCExpression arg) {
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/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> {
+      T makeT() {
+        return new T(); //error
+      }
+    }
+
+    static class D<S> {
+      C<S> makeC() {
+        return new C<S>(); //ok
+      }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/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> {
+      T makeT() {
+        return new T<>(); //error
+      }
+    }
+
+    static class D<S> {
+      C<S> makeC() {
+        return new C<>(); //ok
+      }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/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<T> { }
+
+    void test() {
+        C<?> c1 = new C<? extends String>();
+        C<?> c2 = new C<? super String>();
+        C<?> c3 = new C<?>();
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/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