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:
parent
d267afd1f4
commit
7cdac47d37
@ -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
|
||||
|
17
test/langtools/tools/javac/analyzer/LambdaWithMethod.java
Normal file
17
test/langtools/tools/javac/analyzer/LambdaWithMethod.java
Normal 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) {}
|
||||
}
|
4
test/langtools/tools/javac/analyzer/LambdaWithMethod.out
Normal file
4
test/langtools/tools/javac/analyzer/LambdaWithMethod.out
Normal file
@ -0,0 +1,4 @@
|
||||
LambdaWithMethod.java:9:28: compiler.warn.potential.lambda.found
|
||||
- compiler.err.warnings.and.werror
|
||||
1 error
|
||||
1 warning
|
Loading…
Reference in New Issue
Block a user