8329115: Crash involving return from inner switch
Reviewed-by: jlahoda
This commit is contained in:
parent
9e566d76d1
commit
4dfcc6df17
@ -2473,6 +2473,9 @@ public class Attr extends JCTree.Visitor {
|
|||||||
log.error(tree.pos(), Errors.RetOutsideMeth);
|
log.error(tree.pos(), Errors.RetOutsideMeth);
|
||||||
} else if (env.info.yieldResult != null) {
|
} else if (env.info.yieldResult != null) {
|
||||||
log.error(tree.pos(), Errors.ReturnOutsideSwitchExpression);
|
log.error(tree.pos(), Errors.ReturnOutsideSwitchExpression);
|
||||||
|
if (tree.expr != null) {
|
||||||
|
attribExpr(tree.expr, env, env.info.yieldResult.pt);
|
||||||
|
}
|
||||||
} else if (!env.info.isLambda &&
|
} else if (!env.info.isLambda &&
|
||||||
!env.info.isNewClass &&
|
!env.info.isNewClass &&
|
||||||
env.enclMethod != null &&
|
env.enclMethod != null &&
|
||||||
|
20
test/langtools/tools/javac/patterns/T8329115.java
Normal file
20
test/langtools/tools/javac/patterns/T8329115.java
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
/**
|
||||||
|
* @test /nodynamiccopyright/
|
||||||
|
* @bug 8329115
|
||||||
|
* @summary Crash involving return from inner switch
|
||||||
|
* @compile/fail/ref=T8329115.out -XDrawDiagnostics -XDdev T8329115.java
|
||||||
|
*/
|
||||||
|
public class T8329115 {
|
||||||
|
record R1() {}
|
||||||
|
record R2() {}
|
||||||
|
|
||||||
|
int test() {
|
||||||
|
return switch (new R1()) {
|
||||||
|
case R1() -> {
|
||||||
|
return switch (new R2()) { // crashes, instead it should just be the error: attempt to return out of a switch expression
|
||||||
|
case R2() -> 1;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
3
test/langtools/tools/javac/patterns/T8329115.out
Normal file
3
test/langtools/tools/javac/patterns/T8329115.out
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
T8329115.java:14:17: compiler.err.return.outside.switch.expression
|
||||||
|
T8329115.java:12:16: compiler.err.switch.expression.no.result.expressions
|
||||||
|
2 errors
|
Loading…
Reference in New Issue
Block a user