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 Dec 20, 2024
1 parent f516604 commit 983f794
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
3 changes: 2 additions & 1 deletion docs/release_notes.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ include::include.adoc[]
* Fix mocking issue with the ByteBuddy MockMaker when using multiple classloaders in Java 21 spockIssue:2017[]
* Fix mocking of final classes via `@SpringBean` and `@SpringSpy` spockIssue:1960[]
* Size of data providers is no longer calculated multiple times but only once
* Fix exception when using `@RepeatUntilFailure` with a data provider with unknown iteration amount. spockPull:2031[]
* Fix exception when using `@RepeatUntilFailure` with a data provider with unknown iteration amount spockPull:2031[]
* Clarified documentation about data providers and `size()` calls spockIssue:2022[]
* Fix compile error with single explicit assert in switch expression branch spockIssue:1845[]

== 2.4-M4 (2024-03-21)

Expand Down
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 983f794

Please sign in to comment.