You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "paulk-asert (via GitHub)" <gi...@apache.org> on 2026/09/13 07:19:30 UTC
[PR] GROOVY-12406: report duplicate case labels in a switch statement [groovy]
paulk-asert opened a new pull request, #2930:
URL: https://github.com/apache/groovy/pull/2930
GROOVY-12289 rejects a repeated constant case label in a switch expression, under @TypeChecked and @CompileStatic alike. It left switch statements out, and marked that boundary with a test asserting the permissive behaviour. Java rejects a duplicate label in either position, so the gap was arbitrary:
@CompileStatic
def m(int x) {
switch (x) {
case 1: return 'a'
case 1: return 'b' // dead: the first arm always wins
default: return 'c'
}
}
The check reads only the selector and the case list, both of which a SwitchStatement has, so it is now shared rather than duplicated. Only labels whose value is statically known are compared, which is the same set the jump-table optimizers key on: int-family, String and enum constants. A label the compiler cannot evaluate, such as a variable or a call, is left to sequential first-match-wins dispatch as before.
Dynamic Groovy is unchanged and still takes the first matching arm, as it is for a switch expression; this is a type-checking diagnostic.
The scope-marking test from GROOVY-12289 is replaced by its inverse plus a dynamic-mode test, and the statement form now has the int, String and enum coverage the expression form already had. No other test in the codebase needed changing, in core or in any subproject.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@groovy.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GROOVY-12406: report duplicate case labels in a switch statement [groovy]
Posted by "testlens-app[bot] (via GitHub)" <gi...@apache.org>.
testlens-app[bot] commented on PR #2930:
URL: https://github.com/apache/groovy/pull/2930#issuecomment-5652201707
## ✅ All tests passed ✅
🏷️ Commit: 5731f8f3966229cc79c9105752b56277153688ed
▶️ Tests: 118851 executed
⚪️ Checks: 32/32 completed
---
_Learn more about TestLens at [testlens.app/docs](https://testlens.app/docs/features/pr-comment/)._
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@groovy.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GROOVY-12406: report duplicate case labels in a switch statement [groovy]
Posted by "codecov-commenter (via GitHub)" <gi...@apache.org>.
codecov-commenter commented on PR #2930:
URL: https://github.com/apache/groovy/pull/2930#issuecomment-5652057738
## [Codecov](https://app.codecov.io/gh/apache/groovy/pull/2930?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
:white_check_mark: All modified and coverable lines are covered by tests.
:white_check_mark: Project coverage is 71.1866%. Comparing base ([`3246257`](https://app.codecov.io/gh/apache/groovy/commit/32462579e2689374115525c2ac3e50a1ad86dfb5?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`5731f8f`](https://app.codecov.io/gh/apache/groovy/commit/5731f8f3966229cc79c9105752b56277153688ed?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
:warning: Report is 8 commits behind head on master.
<details><summary>Additional details and impacted files</summary>
[](https://app.codecov.io/gh/apache/groovy/pull/2930?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
```diff
@@ Coverage Diff @@
## master #2930 +/- ##
==================================================
- Coverage 71.1971% 71.1866% -0.0104%
- Complexity 37729 37732 +3
==================================================
Files 1584 1584
Lines 136500 136513 +13
Branches 25361 25368 +7
==================================================
- Hits 97184 97179 -5
- Misses 30546 30552 +6
- Partials 8770 8782 +12
```
| [Files with missing lines](https://app.codecov.io/gh/apache/groovy/pull/2930?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
|---|---|---|
| [...roovy/transform/stc/StaticTypeCheckingVisitor.java](https://app.codecov.io/gh/apache/groovy/pull/2930?src=pr&el=tree&filepath=src%2Fmain%2Fjava%2Forg%2Fcodehaus%2Fgroovy%2Ftransform%2Fstc%2FStaticTypeCheckingVisitor.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3JjL21haW4vamF2YS9vcmcvY29kZWhhdXMvZ3Jvb3Z5L3RyYW5zZm9ybS9zdGMvU3RhdGljVHlwZUNoZWNraW5nVmlzaXRvci5qYXZh) | `87.1964% <100.0000%> (+0.0030%)` | :arrow_up: |
... and [11 files with indirect coverage changes](https://app.codecov.io/gh/apache/groovy/pull/2930/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
</details>
<details><summary> :rocket: New features to boost your workflow: </summary>
- :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
- :package: [JS Bundle Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis): Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
</details>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@groovy.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GROOVY-12406: report duplicate case labels in a switch statement [groovy]
Posted by "paulk-asert (via GitHub)" <gi...@apache.org>.
paulk-asert merged PR #2930:
URL: https://github.com/apache/groovy/pull/2930
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@groovy.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org