Skip to content

Commit

Permalink
Fix compile error with single explicit assert in switch expression br…
Browse files Browse the repository at this point in the history
  • Loading branch information
Vampire committed Oct 29, 2024
1 parent c6964d7 commit a2300a6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,12 @@ public final void visitClosureExpression(ClosureExpression expr) {
currSpecialMethodCall = NoSpecialMethodCall.INSTANCE; // unrelated closure terminates currSpecialMethodCall scope
}
try {
Statement code = expr.getCode();
if (!(code instanceof BlockStatement)) {
BlockStatement block = new BlockStatement();
block.addStatement(code);
expr.setCode(block);
}
doVisitClosureExpression(expr);
} finally {
currClosure = oldClosure;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,14 @@ class ConditionG4Spec extends Specification {
(0..<5) == [0, 1, 2, 3, 4]
(0<..<5) == [1, 2, 3, 4]
}

@Issue("https://github.com/spockframework/spock/issues/1845")
def "explicit assert in switch expression"() {
expect:
def b = 3
!!switch (b) {
case 3 -> assert 1 == 1
default -> assert 1 == 1
}
}
}

0 comments on commit a2300a6

Please sign in to comment.