Skip to content

GROOVY-12035: Avoid emitting unreachable GOTO in if/else bytecode generation#2556

Merged
daniellansun merged 1 commit into
masterfrom
GROOVY-12035
May 24, 2026
Merged

GROOVY-12035: Avoid emitting unreachable GOTO in if/else bytecode generation#2556
daniellansun merged 1 commit into
masterfrom
GROOVY-12035

Conversation

@daniellansun
Copy link
Copy Markdown
Contributor

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented May 23, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 68.1958%. Comparing base (5318145) to head (797b022).
⚠️ Report is 5 commits behind head on master.

Additional details and impacted files

Impacted file tree graph

@@                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     
Files with missing lines Coverage Δ
.../codehaus/groovy/classgen/asm/StatementWriter.java 96.9310% <100.0000%> (+0.0079%) ⬆️

... and 8 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 exitPath emission in if/else bytecode generation with maybeFallsThrough(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.

@testlens-app
Copy link
Copy Markdown

testlens-app Bot commented May 23, 2026

✅ All tests passed ✅

⚠️ TestLens detected flakiness ⚠️

Test Summary

Check Project/Task Test Runs
Build and test / lts (17, ubuntu-latest) :groovy-groovysh:test HelpCommandTest > helpListsKnownCommands() ❌ ✅

🏷️ Commit: 797b022
▶️ Tests: 119732 executed
⚪️ Checks: 57/57 completed


Learn more about TestLens at testlens.app.

@sonarqubecloud
Copy link
Copy Markdown

@daniellansun daniellansun merged commit 3818298 into master May 24, 2026
73 of 77 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants