8191981: javac crash when detecting lambda candidates

Ensuring proper positions on the testing AST nodes created by Analyzer.

Reviewed-by: mcimadamore
This commit is contained in:
Jan Lahoda 2017-11-29 14:41:09 +01:00
parent d267afd1f4
commit 7cdac47d37
3 changed files with 26 additions and 3 deletions

View File

@ -63,6 +63,7 @@ import com.sun.tools.javac.util.List;
import com.sun.tools.javac.util.ListBuffer;
import com.sun.tools.javac.util.Log;
import com.sun.tools.javac.util.Options;
import com.sun.tools.javac.util.Position;
import java.util.EnumSet;
import java.util.HashMap;
@ -305,7 +306,7 @@ public class Analyzer {
JCMethodDecl md = (JCMethodDecl)decls(oldTree.def).head;
List<JCVariableDecl> params = md.params;
JCBlock body = md.body;
JCLambda newTree = make.Lambda(params, body);
JCLambda newTree = make.at(oldTree).Lambda(params, body);
return List.of(newTree);
}
@ -418,7 +419,7 @@ public class Analyzer {
List<JCEnhancedForLoop> rewrite(JCEnhancedForLoop oldTree) {
JCEnhancedForLoop newTree = copier.copy(oldTree);
newTree.var = rewriteVarType(oldTree.var);
newTree.body = make.Block(0, List.nil());
newTree.body = make.at(oldTree.body).Block(0, List.nil());
return List.of(newTree);
}
@Override
@ -551,7 +552,8 @@ public class Analyzer {
JCStatement treeToAnalyze = (JCStatement)rewriting.originalTree;
if (rewriting.env.info.scope.owner.kind == Kind.TYP) {
//add a block to hoist potential dangling variable declarations
treeToAnalyze = make.Block(Flags.SYNTHETIC, List.of((JCStatement)rewriting.originalTree));
treeToAnalyze = make.at(Position.NOPOS)
.Block(Flags.SYNTHETIC, List.of((JCStatement)rewriting.originalTree));
}
//TODO: to further refine the analysis, try all rewriting combinations

View File

@ -0,0 +1,17 @@
/**
* @test /nodynamiccopyright/
* @bug 8191981
* @compile/fail/ref=LambdaWithMethod.out -Werror -XDrawDiagnostics -XDfind=lambda LambdaWithMethod.java
*/
public class LambdaWithMethod {
public static void run(Runnable r) {
run(new Runnable() {
public void run() {
put(get());
}
});
}
private static String get() { return null; }
private static void put(String i) {}
}

View File

@ -0,0 +1,4 @@
LambdaWithMethod.java:9:28: compiler.warn.potential.lambda.found
- compiler.err.warnings.and.werror
1 error
1 warning