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

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

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

   ## 
[Codecov](https://app.codecov.io/gh/apache/groovy/pull/2975?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 `85.00000%` with `6 lines` in your changes missing 
coverage. Please review.
   :white_check_mark: Project coverage is 71.6084%. Comparing base 
([`5d37b46`](https://app.codecov.io/gh/apache/groovy/commit/5d37b46bbec1750910a9959bc155345f2e91d515?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache))
 to head 
([`c585b13`](https://app.codecov.io/gh/apache/groovy/commit/c585b133afd71ed8a512a665f2a728e30240d159?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
   
   | [Files with missing 
lines](https://app.codecov.io/gh/apache/groovy/pull/2975?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
 | Patch % | Lines |
   |---|---|---|
   | 
[...roovy/transform/stc/StaticTypeCheckingVisitor.java](https://app.codecov.io/gh/apache/groovy/pull/2975?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)
 | 85.0000% | [3 Missing and 3 partials :warning: 
](https://app.codecov.io/gh/apache/groovy/pull/2975?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/2975/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/2975?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
   
   ```diff
   @@                Coverage Diff                 @@
   ##               master      #2975        +/-   ##
   ==================================================
   - Coverage     71.6089%   71.6084%   -0.0005%     
   - Complexity      38063      38080        +17     
   ==================================================
     Files            1588       1588                
     Lines          137078     137118        +40     
     Branches        25507      25520        +13     
   ==================================================
   + Hits            98160      98188        +28     
   - Misses          30014      30019         +5     
   - Partials         8904       8911         +7     
   ```
   
   | [Files with missing 
lines](https://app.codecov.io/gh/apache/groovy/pull/2975?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/2975?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.1759% <85.0000%> (-0.0205%)` | :arrow_down: |
   
   ... and [12 files with indirect coverage 
changes](https://app.codecov.io/gh/apache/groovy/pull/2975/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>




> STC: treat a complete native sealed type-case set as an exhaustive switch 
> expression
> ------------------------------------------------------------------------------------
>
>                 Key: GROOVY-12447
>                 URL: https://issues.apache.org/jira/browse/GROOVY-12447
>             Project: Groovy
>          Issue Type: Improvement
>            Reporter: Daniel Sun
>            Priority: Major
>
> h2. Context
> GROOVY-12255 compiles switch expressions as first-class AST ([JEP 
> 361|https://openjdk.org/jeps/361]). Under {{@TypeChecked}} and 
> {{@CompileStatic}}, a switch expression is exhaustive when it has a 
> {{default}} arm, or when the selector is an enum and every constant is listed.
> Native sealed types (GROOVY-10148, GROOVY-10233, [JEP 
> 409|https://openjdk.org/jeps/409]) are a closed hierarchy when the target 
> bytecode is JDK 17+ and the sealed mode is native. Their permitted subclasses 
> are known at compile time, the same way enum constants are.
> Groovy already matches {{case Circle}} with {{isCase}} 
> ({{Class.isInstance}}). That type-case form is what this issue uses.
> h2. Problem
> STC rejects a switch expression that names every permitted subclass of a 
> native sealed selector:
> {code:groovy}
> sealed interface Shape permits Circle, Square {}
> final class Circle implements Shape {}
> final class Square implements Shape {}
> String name(Shape s) {
>     return switch (s) {
>         case Circle -> 'c'
>         case Square -> 's'
>     }
> }
> {code}
> The error is {{the switch expression does not cover all possible input 
> values}}. The same program is legal in Java with type patterns ([JEP 
> 441|https://openjdk.org/jeps/441]). Enums already receive this treatment in 
> Groovy.
> h2. Contract
> A switch expression with no {{default}} is exhaustive when the selector type 
> is native sealed and every remaining inhabitant is covered by a {{case Type}} 
> label.
> Inhabitants of the selector are its permitted subclasses, plus the selector 
> type itself when that type is a concrete class.
> A type-case label that names a member of the hierarchy removes remaining 
> inhabitants that are that type or a subtype of it. {{case Circle, Square}} is 
> two labels (the parser emits one {{CaseStatement}} per value). {{case Rect}} 
> covers nested {{Square}} and {{Triangle}}. {{case Square}} and {{case 
> Triangle}} leave {{Rect}} remaining.
> A label outside the hierarchy, including {{case Object}}, is ordinary 
> {{isCase}} and leaves the remaining set unchanged.
> Native sealed is detected as follows:
> * source: {{SealedASTTransformation.wouldBeNativeSealed}} (JDK 17+ target 
> bytecode and native mode), independent of transform order
> * class file: a non-empty permitted-subclass list (the 
> {{PermittedSubclasses}} attribute). Emulated sealed class files keep a 
> runtime {{@Sealed}} and leave that list empty.
> Duplicate permitted-subclass labels reuse the GROOVY-12289 / GROOVY-12406 
> check. The key is the pair (selector type, binary name), so {{case Circle}} 
> and {{case 'Circle'}} are distinct. That check already runs for switch 
> expressions and switch statements.
> ||Selector and labels||Today||This change||
> |native sealed interface, every permitted type|error|exhaustive|
> |one permitted type omitted|error|error|
> |emulated sealed, every permitted type|error|error|
> |concrete {{sealed class}}, subclasses only|error|error|
> |{{case Shape}} on a {{Shape}} selector|error|exhaustive|
> |{{case Object}} only|error|error|
> |{{case Circle}} and {{case Rect}} ({{Rect}} permits {{Square}}, 
> {{Triangle}})|error|exhaustive|
> |{{case Circle}}, {{case Square}}, {{case Triangle}} ({{Rect}} still 
> permitted)|error|error|
> |native sealed type from a class file, every permitted type|error|exhaustive|
> |switch statement, partial type cases|compiles|compiles|
> |enum, every constant (GROOVY-12255)|exhaustive|exhaustive|
> |duplicate {{case Circle}}|compiles|error: {{Duplicate case label: Circle}}|
> A concrete sealed class is itself an inhabitant:
> {code:groovy}
> sealed class Shape permits Circle, Square {}
> final class Circle extends Shape {}
> final class Square extends Shape {}
> String name(Shape s) {
>     return switch (s) {
>         case Circle -> 'c'
>         case Square -> 's'
>     }
> }
> {code}
> STC still reports {{the switch expression does not cover all possible input 
> values}}, because {{new Shape()}} is legal. {{case Shape}} covers the whole 
> hierarchy.
> Switch statements may be partial. Emulated sealed ({{@SealedOptions(mode = 
> SealedMode.EMULATE)}}) still needs a {{default}} arm. Dynamic Groovy still 
> throws {{IllegalStateException}} for an unmatched selector. Null stays 
> outside this check, matching enum exhaustiveness.
> h2. Touch points
> * {{org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor}} — 
> {{coversAllPermittedSubclasses}}, {{nativeSealedClosed}}, 
> {{permittedSubclassLabelKey}}
> * {{src/test/groovy/groovy/transform/stc/SwitchExpressionSTCTest.groovy}}
> h2. Scope
> This issue covers STC exhaustiveness of native sealed type-case labels, and 
> duplicate detection of those labels. GEP-19 pattern matching, flow typing of 
> the matched arm (GROOVY-12300), and bytecode dispatch for type cases are 
> separate work.



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

Reply via email to