8011432: javac, compiler regression iterable + captured type
authorvromero
Wed, 10 Apr 2013 12:31:02 +0100
changeset 16965 e00f419042b7
parent 16964 096de5815398
child 16966 3d789a69dc81
8011432: javac, compiler regression iterable + captured type Reviewed-by: mcimadamore
langtools/src/share/classes/com/sun/tools/javac/comp/Lower.java
langtools/test/tools/javac/T5053846/MethodRefDupInConstantPoolTest.java
--- a/langtools/src/share/classes/com/sun/tools/javac/comp/Lower.java	Tue Apr 09 14:18:22 2013 -0700
+++ b/langtools/src/share/classes/com/sun/tools/javac/comp/Lower.java	Wed Apr 10 12:31:02 2013 +0100
@@ -48,6 +48,7 @@
 import static com.sun.tools.javac.code.TypeTag.*;
 import static com.sun.tools.javac.jvm.ByteCodes.*;
 import static com.sun.tools.javac.tree.JCTree.Tag.*;
+import javax.lang.model.type.TypeKind;
 
 /** This pass translates away some syntactic sugar: inner classes,
  *  class literals, assertions, foreach loops, etc.
@@ -3400,8 +3401,11 @@
             if (iterableType.getTypeArguments().nonEmpty())
                 iteratorTarget = types.erasure(iterableType.getTypeArguments().head);
             Type eType = tree.expr.type;
+            while (eType.hasTag(TYPEVAR)) {
+                eType = eType.getUpperBound();
+            }
             tree.expr.type = types.erasure(eType);
-            if (eType.hasTag(TYPEVAR) && eType.getUpperBound().isCompound())
+            if (eType.isCompound())
                 tree.expr = make.TypeCast(types.erasure(iterableType), tree.expr);
             Symbol iterator = lookupMethod(tree.expr.pos(),
                                            names.iterator,
--- a/langtools/test/tools/javac/T5053846/MethodRefDupInConstantPoolTest.java	Tue Apr 09 14:18:22 2013 -0700
+++ b/langtools/test/tools/javac/T5053846/MethodRefDupInConstantPoolTest.java	Wed Apr 10 12:31:02 2013 +0100
@@ -23,8 +23,9 @@
 
 /*
  * @test
- * @bug 5053846
+ * @bug 5053846 8011432
  * @summary javac: MethodRef entries are duplicated in the constant pool
+ * @summary javac, compiler regression iterable + captured type
  */
 
 import java.io.PrintWriter;
@@ -43,9 +44,13 @@
 
     void run() {
         check("-v", Paths.get(System.getProperty("test.classes"),
-                "TestHelper1.class").toString());
+                this.getClass().getSimpleName() + "$TestHelper1.class").toString());
+        check("-v", Paths.get(System.getProperty("test.classes"),
+                this.getClass().getSimpleName() + "$TestHelper2.class").toString());
         check("-v", Paths.get(System.getProperty("test.classes"),
-                "TestHelper2.class").toString());
+                this.getClass().getSimpleName() + "$TestHelper3.class").toString());
+        check("-v", Paths.get(System.getProperty("test.classes"),
+                this.getClass().getSimpleName() + "$TestHelper4.class").toString());
     }
 
     void check(String... params) {
@@ -68,24 +73,38 @@
         int end = out.indexOf("{");
         return out.substring(start, end);
     }
-}
 
-class TestHelper1 {
-    void m() {
-        Vector v = new Vector();
-        Iterator iter = v.iterator();
-        while (iter.hasNext()) {
-            Object o = iter.next();
-            Object o2 = o;
-        }
-        for (Object o: v) {
-            Object o2 = o;
+    class TestHelper1 {
+        void m() {
+            Vector v = new Vector();
+            Iterator iter = v.iterator();
+            while (iter.hasNext()) {
+                Object o = iter.next();
+                Object o2 = o;
+            }
+            for (Object o: v) {
+                Object o2 = o;
+            }
         }
     }
-}
+
+    class TestHelper2<X extends Number & Iterable<String>> {
+        void test(X x) {
+            for (String s : x) { }
+        }
+    }
+
+    interface Data extends Iterable<String> {}
 
-class TestHelper2<X extends Number & Iterable<String>> {
-    void test(X x) {
-        for (String s : x) { }
+    class TestHelper3<X extends Number & Iterable<? extends Data>> {
+        void test(X x) {
+            for (Data s : x) { }
+        }
+    }
+
+    class TestHelper4 {
+         void test(Iterable<? extends Data> t) {
+             for(Object a: t.iterator().next());
+         }
     }
 }