Skip to content

GROOVY-11754: STC: prevent cast exception under imbalanced instanceof#2397

Open
eric-milles wants to merge 1 commit intoGROOVY_5_0_Xfrom
GROOVY-11754
Open

GROOVY-11754: STC: prevent cast exception under imbalanced instanceof#2397
eric-milles wants to merge 1 commit intoGROOVY_5_0_Xfrom
GROOVY-11754

Conversation

@eric-milles
Copy link
Member

Changes to StaticTypesTypeChooser in Groovy 5 caused a cast exception at runtime for statically-compiled imbalanced-instanceof scenarios like if (cn instanceof InnerClassNode || cn.isEnum()). This traces back to the temp types storage in STC. For the statement above, only InnerClassNode is saved as a temp type. When the temp type is computed for "cn.isEnum()", InnerClassNode is the result.

A small part of the GROOVY-7971 solution is to mix in the original variable type in a scenario such as this -- to express the optionality of instance check(s). I back-ported just this part of the larger solution. This stops the cast exception for the GROOVY-11754 scenario. This is a pre-condition for introducing the GROOVY-11769 StaticTypesTypeChooser change (see #2311) into Groovy 4.

@eric-milles eric-milles requested a review from paulk-asert March 19, 2026 16:49
@codecov-commenter
Copy link

codecov-commenter commented Mar 19, 2026

Codecov Report

❌ Patch coverage is 85.71429% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 67.1339%. Comparing base (7d36495) to head (781f35e).

Files with missing lines Patch % Lines
...roovy/transform/stc/StaticTypeCheckingVisitor.java 85.7143% 0 Missing and 5 partials ⚠️
Additional details and impacted files

Impacted file tree graph

@@                  Coverage Diff                   @@
##             GROOVY_5_0_X      #2397        +/-   ##
======================================================
+ Coverage         67.1286%   67.1339%   +0.0053%     
- Complexity          29422      29430         +8     
======================================================
  Files                1382       1382                
  Lines              116758     116789        +31     
  Branches            20462      20471         +9     
======================================================
+ Hits                78378      78405        +27     
- Misses              31902      31903         +1     
- Partials             6478       6481         +3     
Files with missing lines Coverage Δ
...roovy/transform/stc/StaticTypeCheckingVisitor.java 87.7494% <85.7143%> (-0.0057%) ⬇️

... and 4 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.

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.

2 participants