8019480: Javac crashes when method is called on a type-variable receiver from lambda expression
authormcimadamore
Fri, 05 Jul 2013 11:02:17 +0100
changeset 18901 8309dd8e14d9
parent 18900 5ed5dd2ee5fe
child 18902 972298345a83
8019480: Javac crashes when method is called on a type-variable receiver from lambda expression Summary: Logic for shortcircuiting speculative attribution doesn't handle type-variable receivers Reviewed-by: jjg, vromero
langtools/src/share/classes/com/sun/tools/javac/comp/DeferredAttr.java
langtools/test/tools/javac/lambda/8019480/T8019480.java
langtools/test/tools/javac/lambda/8019480/T8019480.out
--- a/langtools/src/share/classes/com/sun/tools/javac/comp/DeferredAttr.java	Fri Jul 05 11:00:19 2013 +0100
+++ b/langtools/src/share/classes/com/sun/tools/javac/comp/DeferredAttr.java	Fri Jul 05 11:02:17 2013 +0100
@@ -941,6 +941,10 @@
                     attribSpeculative(rec, env, attr.unknownTypeExprInfo).type :
                     env.enclClass.sym.type;
 
+            while (site.hasTag(TYPEVAR)) {
+                site = site.getUpperBound();
+            }
+
             ListBuffer<Type> args = ListBuffer.lb();
             for (int i = 0; i < tree.args.length(); i ++) {
                 args.append(Type.noType);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/lambda/8019480/T8019480.java	Fri Jul 05 11:02:17 2013 +0100
@@ -0,0 +1,23 @@
+/*
+ * @test /nodynamiccopyright/
+ * @bug 8019480
+ * @summary Javac crashes when method is called on a type-variable receiver from lambda expression
+ * @author  Maurizio Cimadamore
+ * @compile/fail/ref=T8019480.out -XDrawDiagnostics T8019480.java
+ */
+import java.util.*;
+
+class T8019480<U> {
+    interface Predicate<T> {
+       void m(T t);
+    }
+
+    interface Stream<T> {
+       void forEach(Predicate<T> pt);
+    }
+
+    void test(U current, Stream<U> stream) {
+        List<U> list3 = new ArrayList<>();
+        stream.forEach(i -> list3.add(current.clone()));
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/lambda/8019480/T8019480.out	Fri Jul 05 11:02:17 2013 +0100
@@ -0,0 +1,3 @@
+T8019480.java:21:46: compiler.err.report.access: clone(), protected, java.lang.Object
+T8019480.java:21:34: compiler.err.cant.apply.symbols: kindname.method, add, java.lang.Object,{(compiler.misc.inapplicable.method: kindname.method, java.util.Collection, add(U), (compiler.misc.no.conforming.assignment.exists: (compiler.misc.inconvertible.types: java.lang.Object, U))),(compiler.misc.inapplicable.method: kindname.method, java.util.List, add(U), (compiler.misc.no.conforming.assignment.exists: (compiler.misc.inconvertible.types: java.lang.Object, U))),(compiler.misc.inapplicable.method: kindname.method, java.util.List, add(int,U), (compiler.misc.arg.length.mismatch))}
+2 errors