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:
Jan Lahoda 2017-06-19 11:41:21 +02:00
parent 6c04ae3d71
commit dfaf30bc4c
4 changed files with 53 additions and 4 deletions

View File

@ -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);
}

View File

@ -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 {

View 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();
}
}

View File

@ -0,0 +1,2 @@
LambdaConv28.java:17:22: compiler.warn.potential.lambda.found
1 warning