mirror of
https://github.com/openjdk/jdk.git
synced 2026-02-05 07:58:40 +00:00
8181911: Lambda Analyzer causes compile-time error
When copying Env<AttrContext> for Analyzer, detach returnResult from the outer context. Reviewed-by: mcimadamore
This commit is contained in:
parent
6c04ae3d71
commit
dfaf30bc4c
@ -336,12 +336,28 @@ public class Analyzer {
|
||||
};
|
||||
|
||||
/**
|
||||
* Analyze an AST node if needed.
|
||||
* Create a copy of Env if needed.
|
||||
*/
|
||||
void analyzeIfNeeded(JCTree tree, Env<AttrContext> env) {
|
||||
Env<AttrContext> copyEnvIfNeeded(JCTree tree, Env<AttrContext> env) {
|
||||
if (!analyzerModes.isEmpty() &&
|
||||
!env.info.isSpeculative &&
|
||||
TreeInfo.isStatement(tree)) {
|
||||
Env<AttrContext> analyzeEnv =
|
||||
env.dup(env.tree, env.info.dup(env.info.scope.dupUnshared(env.info.scope.owner)));
|
||||
analyzeEnv.info.returnResult = analyzeEnv.info.returnResult != null ?
|
||||
attr.new ResultInfo(analyzeEnv.info.returnResult.pkind,
|
||||
analyzeEnv.info.returnResult.pt) : null;
|
||||
return analyzeEnv;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Analyze an AST node if needed.
|
||||
*/
|
||||
void analyzeIfNeeded(JCTree tree, Env<AttrContext> env) {
|
||||
if (env != null) {
|
||||
JCStatement stmt = (JCStatement)tree;
|
||||
analyze(stmt, env);
|
||||
}
|
||||
|
||||
@ -718,8 +718,7 @@ public class Attr extends JCTree.Visitor {
|
||||
/** Derived visitor method: attribute a statement or definition tree.
|
||||
*/
|
||||
public Type attribStat(JCTree tree, Env<AttrContext> env) {
|
||||
Env<AttrContext> analyzeEnv =
|
||||
env.dup(tree, env.info.dup(env.info.scope.dupUnshared(env.info.scope.owner)));
|
||||
Env<AttrContext> analyzeEnv = analyzer.copyEnvIfNeeded(tree, env);
|
||||
try {
|
||||
return attribTree(tree, env, statInfo);
|
||||
} finally {
|
||||
|
||||
32
langtools/test/tools/javac/lambda/LambdaConv28.java
Normal file
32
langtools/test/tools/javac/lambda/LambdaConv28.java
Normal file
@ -0,0 +1,32 @@
|
||||
/*
|
||||
* @test /nodynamiccopyright/
|
||||
* @bug 8181911
|
||||
* @summary Verify that the analyzer does not affect ordinary compilation.
|
||||
* @compile/ref=LambdaConv28.out -XDrawDiagnostics -XDfind=lambda LambdaConv28.java
|
||||
*/
|
||||
|
||||
class LambdaConv28 {
|
||||
|
||||
public void test(A a) {
|
||||
test(()-> {
|
||||
return new I() {
|
||||
public <T> void t() {
|
||||
}
|
||||
};
|
||||
});
|
||||
test(new A() {
|
||||
public I get() {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public interface I {
|
||||
public <T> void t();
|
||||
}
|
||||
|
||||
public interface A {
|
||||
public I get();
|
||||
}
|
||||
|
||||
}
|
||||
2
langtools/test/tools/javac/lambda/LambdaConv28.out
Normal file
2
langtools/test/tools/javac/lambda/LambdaConv28.out
Normal file
@ -0,0 +1,2 @@
|
||||
LambdaConv28.java:17:22: compiler.warn.potential.lambda.found
|
||||
1 warning
|
||||
Loading…
x
Reference in New Issue
Block a user