changeset 2398:a4be2c2fe0a1

8011432: javac, compiler regression iterable + captured type Reviewed-by: mcimadamore
author vromero
date Wed, 10 Apr 2013 12:31:02 +0100
parents eb134c8e931d
children 9a7967dcfb03 d13af7751456
files src/share/classes/com/sun/tools/javac/comp/Lower.java test/tools/javac/T5053846/MethodRefDupInConstantPoolTest.java
diffstat 2 files changed, 42 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/com/sun/tools/javac/comp/Lower.java	Tue Apr 09 14:18:22 2013 -0700
+++ b/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/test/tools/javac/T5053846/MethodRefDupInConstantPoolTest.java	Tue Apr 09 14:18:22 2013 -0700
+++ b/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"),
-                "TestHelper2.class").toString());
+                this.getClass().getSimpleName() + "$TestHelper2.class").toString());
+        check("-v", Paths.get(System.getProperty("test.classes"),
+                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) { }
+    class TestHelper2<X extends Number & Iterable<String>> {
+        void test(X x) {
+            for (String s : x) { }
+        }
+    }
+
+    interface Data extends Iterable<String> {}
+
+    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());
+         }
     }
 }