8067792: Javac crashes in finder mode with nested implicit lambdas
authormcimadamore
Wed, 17 Dec 2014 16:47:56 +0000
changeset 28146 adf3a039cb7d
parent 28145 365419055307
child 28147 72e7fdc79b78
8067792: Javac crashes in finder mode with nested implicit lambdas Summary: Revert tree changes occurred in Attr before running the analyzer Reviewed-by: jlahoda
langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Analyzer.java
langtools/test/tools/javac/lambda/8067792/T8067792.java
langtools/test/tools/javac/lambda/8067792/T8067792.out
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Analyzer.java	Wed Dec 17 12:49:57 2014 +0100
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Analyzer.java	Wed Dec 17 16:47:56 2014 +0000
@@ -25,6 +25,7 @@
 
 package com.sun.tools.javac.comp;
 
+import com.sun.source.tree.LambdaExpressionTree;
 import com.sun.tools.javac.code.Source;
 import com.sun.tools.javac.code.Type;
 import com.sun.tools.javac.code.Types;
@@ -36,6 +37,7 @@
 import com.sun.tools.javac.tree.JCTree.JCForLoop;
 import com.sun.tools.javac.tree.JCTree.JCIf;
 import com.sun.tools.javac.tree.JCTree.JCLambda;
+import com.sun.tools.javac.tree.JCTree.JCLambda.ParameterKind;
 import com.sun.tools.javac.tree.JCTree.JCMethodDecl;
 import com.sun.tools.javac.tree.JCTree.JCMethodInvocation;
 import com.sun.tools.javac.tree.JCTree.JCNewClass;
@@ -50,6 +52,8 @@
 import com.sun.tools.javac.tree.TreeMaker;
 import com.sun.tools.javac.tree.TreeScanner;
 import com.sun.tools.javac.util.Context;
+import com.sun.tools.javac.util.DefinedBy;
+import com.sun.tools.javac.util.DefinedBy.Api;
 import com.sun.tools.javac.util.Filter;
 import com.sun.tools.javac.util.JCDiagnostic;
 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticType;
@@ -489,5 +493,17 @@
             }
             return newTree;
         }
+
+        @Override @DefinedBy(Api.COMPILER_TREE)
+        public JCTree visitLambdaExpression(LambdaExpressionTree node, Void _unused) {
+            JCLambda oldLambda = (JCLambda)node;
+            JCLambda newLambda = (JCLambda)super.visitLambdaExpression(node, _unused);
+            if (oldLambda.paramKind == ParameterKind.IMPLICIT) {
+                //reset implicit lambda parameters (whose type might have been set during attr)
+                newLambda.paramKind = ParameterKind.IMPLICIT;
+                newLambda.params.forEach(p -> p.vartype = null);
+            }
+            return newLambda;
+        }
     }
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/lambda/8067792/T8067792.java	Wed Dec 17 16:47:56 2014 +0000
@@ -0,0 +1,19 @@
+/*
+ * @test /nodynamiccopyright/
+ * @bug 8067792
+ * @summary Javac crashes in finder mode with nested implicit lambdas
+ * @compile/fail/ref=T8067792.out -XDrawDiagnostics -Werror -XDfind=lambda T8067792.java
+ */
+
+import java.util.stream.*;
+import java.util.*;
+
+class T8067792 {
+    void test(Stream<List<?>> sl) {
+        Runnable r = new Runnable() {
+            public void run() {
+                Stream<List<?>> constructor = sl.filter(c -> true);
+            }
+        };
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/lambda/8067792/T8067792.out	Wed Dec 17 16:47:56 2014 +0000
@@ -0,0 +1,4 @@
+T8067792.java:13:37: compiler.warn.potential.lambda.found
+- compiler.err.warnings.and.werror
+1 error
+1 warning