[ 
https://issues.apache.org/jira/browse/GROOVY-12289?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18107020#comment-18107020
 ] 

ASF GitHub Bot commented on GROOVY-12289:
-----------------------------------------

codecov-commenter commented on PR #2826:
URL: https://github.com/apache/groovy/pull/2826#issuecomment-5383397998

   ## 
[Codecov](https://app.codecov.io/gh/apache/groovy/pull/2826?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
 Report
   :x: Patch coverage is `87.50000%` with `2 lines` in your changes missing 
coverage. Please review.
   :white_check_mark: Project coverage is 70.2651%. Comparing base 
([`01f91d4`](https://app.codecov.io/gh/apache/groovy/commit/01f91d475918156df6c290460c70e3c7dfbe1e36?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache))
 to head 
([`7dedae9`](https://app.codecov.io/gh/apache/groovy/commit/7dedae97d7020e6c3e05f374f1a9f0be94fd3515?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
   :warning: Report is 1 commits behind head on master.
   
   | [Files with missing 
lines](https://app.codecov.io/gh/apache/groovy/pull/2826?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
 | Patch % | Lines |
   |---|---|---|
   | 
[...sgen/asm/sc/StaticTypesSwitchExpressionWriter.java](https://app.codecov.io/gh/apache/groovy/pull/2826?src=pr&el=tree&filepath=src%2Fmain%2Fjava%2Forg%2Fcodehaus%2Fgroovy%2Fclassgen%2Fasm%2Fsc%2FStaticTypesSwitchExpressionWriter.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3JjL21haW4vamF2YS9vcmcvY29kZWhhdXMvZ3Jvb3Z5L2NsYXNzZ2VuL2FzbS9zYy9TdGF0aWNUeXBlc1N3aXRjaEV4cHJlc3Npb25Xcml0ZXIuamF2YQ==)
 | 75.0000% | [0 Missing and 1 partial :warning: 
](https://app.codecov.io/gh/apache/groovy/pull/2826?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
 |
   | 
[...roovy/transform/stc/StaticTypeCheckingVisitor.java](https://app.codecov.io/gh/apache/groovy/pull/2826?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)
 | 91.6667% | [0 Missing and 1 partial :warning: 
](https://app.codecov.io/gh/apache/groovy/pull/2826?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
 |
   
   <details><summary>Additional details and impacted files</summary>
   
   
   
   [![Impacted file tree 
graph](https://app.codecov.io/gh/apache/groovy/pull/2826/graphs/tree.svg?width=650&height=150&src=pr&token=1r45138NfQ&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)](https://app.codecov.io/gh/apache/groovy/pull/2826?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
   
   ```diff
   @@                Coverage Diff                 @@
   ##               master      #2826        +/-   ##
   ==================================================
   + Coverage     70.2594%   70.2651%   +0.0057%     
   - Complexity      36274      36283         +9     
   ==================================================
     Files            1569       1569                
     Lines          133723     133725         +2     
     Branches        24637      24638         +1     
   ==================================================
   + Hits            93953      93962         +9     
   + Misses          31257      31249         -8     
   - Partials         8513       8514         +1     
   ```
   
   | [Files with missing 
lines](https://app.codecov.io/gh/apache/groovy/pull/2826?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
 | Coverage Δ | |
   |---|---|---|
   | 
[...sgen/asm/sc/StaticTypesSwitchExpressionWriter.java](https://app.codecov.io/gh/apache/groovy/pull/2826?src=pr&el=tree&filepath=src%2Fmain%2Fjava%2Forg%2Fcodehaus%2Fgroovy%2Fclassgen%2Fasm%2Fsc%2FStaticTypesSwitchExpressionWriter.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3JjL21haW4vamF2YS9vcmcvY29kZWhhdXMvZ3Jvb3Z5L2NsYXNzZ2VuL2FzbS9zYy9TdGF0aWNUeXBlc1N3aXRjaEV4cHJlc3Npb25Xcml0ZXIuamF2YQ==)
 | `93.9394% <75.0000%> (+0.1894%)` | :arrow_up: |
   | 
[...roovy/transform/stc/StaticTypeCheckingVisitor.java](https://app.codecov.io/gh/apache/groovy/pull/2826?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.1972% <91.6667%> (+0.0133%)` | :arrow_up: |
   
   ... and [10 files with indirect coverage 
changes](https://app.codecov.io/gh/apache/groovy/pull/2826/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>




> Switch expressions with duplicate case labels compile under @TypeChecked but 
> fail under @CompileStatic
> ------------------------------------------------------------------------------------------------------
>
>                 Key: GROOVY-12289
>                 URL: https://issues.apache.org/jira/browse/GROOVY-12289
>             Project: Groovy
>          Issue Type: Bug
>            Reporter: Paul King
>            Assignee: Paul King
>            Priority: Minor
>
> Switch expressions with duplicate constant case labels compile under 
> {{@TypeChecked}} (and dynamic Groovy) but fail under {{@CompileStatic}}:
> {code:groovy}
> def m(int x) {
>     def r = switch (x) {
>         case 1 -> 'a'
>         case 1 -> 'b'   // dead code: first match wins
>         default -> 'c'
>     }
>     r
> }
> {code}
> Dynamic and {{@TypeChecked}}: compiles; sequential {{isCase}} semantics mean 
> the first matching arm wins. {{@CompileStatic}}: fails with {{Duplicate case 
> label: 1}}, raised from {{StaticTypesSwitchExpressionWriter}} when the 
> tableswitch/lookupswitch optimizer finds a repeated key. Reproduces for 
> int-family, String and enum constant labels.
> Two problems:
> # *Mode divergence.* Whether the code compiles should not depend on the 
> compilation mode (or on whether a bytecode optimizer happens to apply — 
> mixing a duplicated constant with a dynamic label, e.g. {{case 1; case 1; 
> case foo()}}, silently disabled the optimizer and compiled fine under 
> {{@CompileStatic}}).
> # *Broken error reporting.* The writer reports the error mid-codegen and then 
> continues, so ASM also reports a processing error on the truncated method — 
> the user sees a confusing secondary failure.
> *Fix:* detect repeated constant labels (int-family, String and enum constants 
> — the same keys the optimizers use, via the shared {{SwitchExpressionUtils}} 
> extractors) in {{StaticTypeCheckingVisitor}}, so {{@TypeChecked}} and 
> {{@CompileStatic}} both report {{[Static type checking] - Duplicate case 
> label: ...}} at the offending label. The static writer no longer errors: a 
> duplicate key just skips the optimizer like any other non-optimizable shape 
> and falls back to sequential first-match-wins dispatch. That path is only 
> reachable when type checking is bypassed ({{TypeCheckingMode.SKIP}} or a 
> type-checking extension), where dynamic semantics are the intent — previously 
> it crashed codegen.
> Unchanged: dynamic Groovy, switch *statements*, and non-constant labels 
> (GStrings, calls, ranges) — those cannot be proven duplicated statically.
> Note one deliberate tightening: duplicated constants mixed with dynamic 
> labels now error in both modes (previously accepted under {{@CompileStatic}} 
> because the optimizer bailed out silently).
> *Escape hatch:* a DSL that wants first-match-wins duplicate labels under 
> {{@TypeChecked}} can opt affected methods out via a type-checking extension 
> ({{beforeVisitMethod \{ mn -> handled = true \}}}); the method then compiles 
> and dispatches dynamically. This is method-granular — there is no per-switch 
> waiver. Covered by a new test using {{Groovy12289Extension.groovy}}.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to