GROOVY-12190: @TypeChecked switch on enum: unqualified case constants… - #2735
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR addresses GROOVY-12190, where @TypeChecked code using unqualified enum constants in switch case labels could pass type checking but fail at runtime with MissingPropertyException, by ensuring those case-label constants are rewritten to qualified EnumType.CONST expressions.
Changes:
- Add a post-typechecking AST rewrite in
StaticTypesTransformationto replace enum case-labelVariableExpressions (tagged by STC) withEnumType.CONSTPropertyExpressions, including traversal into closures (needed for switch expressions). - Add regression tests covering
switchstatements, switch-expression (case A ->), nested switch-expressions, and closure-contained switches under@TypeChecked.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/test/groovy/bugs/Groovy8444.groovy |
Adds GROOVY-12190 regression tests for enum switch case constants under @TypeChecked. |
src/main/java/org/codehaus/groovy/transform/StaticTypesTransformation.java |
Rewrites enum switch case-label constants after STC to avoid runtime dynamic property lookup failures. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #2735 +/- ##
==================================================
+ Coverage 69.2916% 69.3420% +0.0504%
- Complexity 34865 35057 +192
==================================================
Files 1546 1551 +5
Lines 130655 131460 +805
Branches 23850 24042 +192
==================================================
+ Hits 90533 91157 +624
- Misses 31960 32061 +101
- Partials 8162 8242 +80
🚀 New features to boost your workflow:
|
This comment has been minimized.
This comment has been minimized.
… pass type checking but throw MissingPropertyException at runtime
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
… pass type checking but throw MissingPropertyException at runtime