Skip to content

GROOVY-12190: @TypeChecked switch on enum: unqualified case constants… - #2735

Merged
paulk-asert merged 1 commit into
apache:masterfrom
paulk-asert:groovy12190
Jul 25, 2026
Merged

GROOVY-12190: @TypeChecked switch on enum: unqualified case constants…#2735
paulk-asert merged 1 commit into
apache:masterfrom
paulk-asert:groovy12190

Conversation

@paulk-asert

Copy link
Copy Markdown
Contributor

… pass type checking but throw MissingPropertyException at runtime

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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-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 StaticTypesTransformation to replace enum case-label VariableExpressions (tagged by STC) with EnumType.CONST PropertyExpressions, including traversal into closures (needed for switch expressions).
  • Add regression tests covering switch statements, 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-commenter

codecov-commenter commented Jul 25, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 89.47368% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 69.3420%. Comparing base (188718f) to head (0e8f39d).
⚠️ Report is 3 commits behind head on master.

Files with missing lines Patch % Lines
...us/groovy/transform/StaticTypesTransformation.java 89.4737% 1 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@                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     
Files with missing lines Coverage Δ
...us/groovy/transform/StaticTypesTransformation.java 87.2727% <89.4737%> (+1.1616%) ⬆️

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

@testlens-app

This comment has been minimized.

… pass type checking but throw MissingPropertyException at runtime
@paulk-asert
paulk-asert merged commit 8fd428c into apache:master Jul 25, 2026
29 checks passed
@paulk-asert
paulk-asert deleted the groovy12190 branch July 25, 2026 04:13
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