[
https://issues.apache.org/jira/browse/GROOVY-12406?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18114743#comment-18114743
]
ASF GitHub Bot commented on GROOVY-12406:
-----------------------------------------
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.
> Duplicate case labels not detected in switch statements
> -------------------------------------------------------
>
> Key: GROOVY-12406
> URL: https://issues.apache.org/jira/browse/GROOVY-12406
> Project: Groovy
> Issue Type: Improvement
> Reporter: Paul King
> Assignee: Paul King
> Priority: Major
>
--
This message was sent by Atlassian Jira
(v8.20.10#820010)