GROOVY-12035: Avoid emitting unreachable GOTO in if/else bytecode generation#2556
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #2556 +/- ##
==================================================
+ Coverage 68.1844% 68.1958% +0.0114%
- Complexity 33086 33099 +13
==================================================
Files 1508 1508
Lines 126130 126147 +17
Branches 22878 22887 +9
==================================================
+ Hits 86001 86027 +26
+ Misses 32490 32486 -4
+ Partials 7639 7634 -5
🚀 New features to boost your workflow:
|
924789f to
797b022
Compare
There was a problem hiding this comment.
Pull request overview
This PR addresses GROOVY-12035 by preventing StatementWriter.writeIfElse from emitting a GOTO that is guaranteed to be unreachable when the if block cannot fall through (e.g., it always returns or throws). This improves generated bytecode quality and avoids dead/unreachable instructions.
Changes:
- Guard the synthetic
GOTO exitPathemission inif/elsebytecode generation withmaybeFallsThrough(ifBlock). - Add a new regression test suite that compiles representative scripts and asserts the produced bytecode has no unreachable instructions (and that runtime behavior remains correct).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/main/java/org/codehaus/groovy/classgen/asm/StatementWriter.java |
Avoids emitting an unreachable GOTO in if/else codegen when the if block can’t fall through. |
src/test/groovy/org/codehaus/groovy/classgen/asm/IfElseBytecodeReachabilityTest.groovy |
Adds regression tests to detect unreachable bytecode for dynamic/static if/else patterns with return/throw. |
✅ All tests passed ✅Test Summary
🏷️ Commit: 797b022 Learn more about TestLens at testlens.app. |
|



https://issues.apache.org/jira/browse/GROOVY-12035