Skip to content

Commit 4dfcc6d

Browse files
committedMar 27, 2024
8329115: Crash involving return from inner switch
Reviewed-by: jlahoda
1 parent 9e566d7 commit 4dfcc6d

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed
 

‎src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java

+3
Original file line numberDiff line numberDiff line change
@@ -2473,6 +2473,9 @@ public void visitReturn(JCReturn tree) {
24732473
log.error(tree.pos(), Errors.RetOutsideMeth);
24742474
} else if (env.info.yieldResult != null) {
24752475
log.error(tree.pos(), Errors.ReturnOutsideSwitchExpression);
2476+
if (tree.expr != null) {
2477+
attribExpr(tree.expr, env, env.info.yieldResult.pt);
2478+
}
24762479
} else if (!env.info.isLambda &&
24772480
!env.info.isNewClass &&
24782481
env.enclMethod != null &&
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* @test /nodynamiccopyright/
3+
* @bug 8329115
4+
* @summary Crash involving return from inner switch
5+
* @compile/fail/ref=T8329115.out -XDrawDiagnostics -XDdev T8329115.java
6+
*/
7+
public class T8329115 {
8+
record R1() {}
9+
record R2() {}
10+
11+
int test() {
12+
return switch (new R1()) {
13+
case R1() -> {
14+
return switch (new R2()) { // crashes, instead it should just be the error: attempt to return out of a switch expression
15+
case R2() -> 1;
16+
};
17+
}
18+
};
19+
}
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
T8329115.java:14:17: compiler.err.return.outside.switch.expression
2+
T8329115.java:12:16: compiler.err.switch.expression.no.result.expressions
3+
2 errors

1 commit comments

Comments
 (1)

openjdk-notifier[bot] commented on Mar 27, 2024

@openjdk-notifier[bot]
Please sign in to comment.