8317336: Assertion error thrown during 'this' escape analysis

Reviewed-by: vromero
This commit is contained in:
Archie Cobbs 2023-10-12 16:51:53 +00:00 committed by Vicente Romero
parent 16fd43c5eb
commit a8473b7079
2 changed files with 25 additions and 2 deletions

View File

@ -678,7 +678,11 @@ class ThisEscapeAnalyzer extends TreeScanner {
@Override
public void visitForeachLoop(JCEnhancedForLoop tree) {
visitLooped(tree, super::visitForeachLoop);
visitLooped(tree, foreach -> {
scan(foreach.expr);
refs.discardExprs(depth); // we don't handle iterator() yet
scan(foreach.body);
});
}
@Override
@ -729,7 +733,10 @@ class ThisEscapeAnalyzer extends TreeScanner {
@Override
public void visitLambda(JCLambda lambda) {
visitDeferred(() -> visitScoped(false, () -> super.visitLambda(lambda)));
visitDeferred(() -> visitScoped(false, () -> {
scan(lambda.body);
refs.discardExprs(depth); // needed in case body is a JCExpression
}));
}
@Override

View File

@ -601,4 +601,20 @@ public class ThisEscape {
public static final class Sub2 extends ThisEscapeSealed {
}
}
// Verify no assertion error occurs (JDK-8317336)
public static class ThisEscapeAssertionError {
public ThisEscapeAssertionError() {
System.out.println((Supplier<Object>)() -> this);
}
}
// Verify no assertion error occurs (JDK-8317336)
public static class ThisEscapeAssertionError2 {
public ThisEscapeAssertionError2() {
ThisEscapeAssertionError2[] array = new ThisEscapeAssertionError2[] { this };
for (Object obj : array)
;
}
}
}