[
https://issues.apache.org/jira/browse/GROOVY-12190?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18099074#comment-18099074
]
ASF GitHub Bot commented on GROOVY-12190:
-----------------------------------------
codecov-commenter commented on PR #2735:
URL: https://github.com/apache/groovy/pull/2735#issuecomment-5076648499
##
[Codecov](https://app.codecov.io/gh/apache/groovy/pull/2735?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 `89.47368%` with `2 lines` in your changes missing
coverage. Please review.
:white_check_mark: Project coverage is 69.2892%. Comparing base
([`188718f`](https://app.codecov.io/gh/apache/groovy/commit/188718fb7cd694a5dfe733d09c61a7352a1c352b?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache))
to head
([`df29e5d`](https://app.codecov.io/gh/apache/groovy/commit/df29e5d5ca542f42f3623b0ec372cc4327f399de?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/2735?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
| Patch % | Lines |
|---|---|---|
|
[...us/groovy/transform/StaticTypesTransformation.java](https://app.codecov.io/gh/apache/groovy/pull/2735?src=pr&el=tree&filepath=src%2Fmain%2Fjava%2Forg%2Fcodehaus%2Fgroovy%2Ftransform%2FStaticTypesTransformation.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3JjL21haW4vamF2YS9vcmcvY29kZWhhdXMvZ3Jvb3Z5L3RyYW5zZm9ybS9TdGF0aWNUeXBlc1RyYW5zZm9ybWF0aW9uLmphdmE=)
| 89.4737% | [1 Missing and 1 partial :warning:
](https://app.codecov.io/gh/apache/groovy/pull/2735?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>
[](https://app.codecov.io/gh/apache/groovy/pull/2735?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
```diff
@@ Coverage Diff @@
## master #2735 +/- ##
==================================================
- Coverage 69.2916% 69.2892% -0.0024%
Complexity 34865 34865
==================================================
Files 1546 1546
Lines 130655 130674 +19
Branches 23850 23855 +5
==================================================
+ Hits 90533 90543 +10
- Misses 31960 31965 +5
- Partials 8162 8166 +4
```
| [Files with missing
lines](https://app.codecov.io/gh/apache/groovy/pull/2735?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
| Coverage Δ | |
|---|---|---|
|
[...us/groovy/transform/StaticTypesTransformation.java](https://app.codecov.io/gh/apache/groovy/pull/2735?src=pr&el=tree&filepath=src%2Fmain%2Fjava%2Forg%2Fcodehaus%2Fgroovy%2Ftransform%2FStaticTypesTransformation.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3JjL21haW4vamF2YS9vcmcvY29kZWhhdXMvZ3Jvb3Z5L3RyYW5zZm9ybS9TdGF0aWNUeXBlc1RyYW5zZm9ybWF0aW9uLmphdmE=)
| `87.2727% <89.4737%> (+1.1616%)` | :arrow_up: |
... and [6 files with indirect coverage
changes](https://app.codecov.io/gh/apache/groovy/pull/2735/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>
> @TypeChecked switch on enum: unqualified case constants pass type checking
> but throw MissingPropertyException at runtime
> ------------------------------------------------------------------------------------------------------------------------
>
> Key: GROOVY-12190
> URL: https://issues.apache.org/jira/browse/GROOVY-12190
> Project: Groovy
> Issue Type: Bug
> Affects Versions: 4.0.32, 6.0.0-alpha-2, 5.0.7
> Reporter: Paul King
> Priority: Major
>
> Since the follow-up refactor for GROOVY-11614 (4.0.28, 5.0.0), unqualified
> enum
> constants in {{switch}} case labels under {{@TypeChecked}} (without static
> compilation) pass type checking but throw {{MissingPropertyException}} at
> runtime. This worked correctly from Groovy 3.0.0-RC-1, where GROOVY-8444 first
> shipped, through 4.0.27.
> h3. Reproducer
> {code:groovy}
> enum Color { RED, GREEN, BLUE }
> @groovy.transform.TypeChecked
> def m(Color c) {
> switch (c) {
> case GREEN: return 'matched'
> default: return 'default'
> }
> }
> assert m(Color.GREEN) == 'matched'
> {code}
> *Expected* (and actual on 3.0.0-RC-1 through 4.0.27): the assert passes.
> *Actual* on 4.0.28+, 5.x and master:
> {noformat}
> groovy.lang.MissingPropertyException: No such property: GREEN for class: repro
> at repro.m(repro.groovy:6)
> at repro.run(repro.groovy:10)
> {noformat}
> The same failure occurs with switch expressions ({{case GREEN -> 'matched'}})
> —
> same root cause, so both forms are covered by this issue. With
> {{@CompileStatic}} both forms work correctly.
> h3. Timeline
> * *2.x*: unqualified enum case constants were never supported; type-checked
> code failed fast with a clean compile-time error:
> {{[Static type checking] - The variable [GREEN] is undeclared.}}
> * *3.0.0-RC-1 → 4.0.27*: works under both {{@TypeChecked}} and
> {{@CompileStatic}} (GROOVY-8444, never backported to 2.x). Switch
> _expressions_ with unqualified constants were broken under both modes until
> GROOVY-11614.
> * *4.0.28+ / 5.0.0+*: GROOVY-11614 fixed switch expressions for
> {{@CompileStatic}}, but its follow-up refactor regressed {{@TypeChecked}} for
> both switch forms to compile-then-runtime-failure — worse than both earlier
> eras, since it fails neither at compile time nor safely.
> h3. Root cause
> {{EnumTypeCheckingExtension#handleUnresolvedVariableExpression}} resolves the
> bare constant during type checking (so no compile error is reported), and the
> follow-up commit for GROOVY-11614 (81098ecb52, "SC: apply enum-case
> transformation after STC visitation") moved the {{CONST}} →
> {{EnumType.CONST}} rewrite from {{CompilationUnit}} into
> {{VariableExpressionTransformer}}, which only runs under static compilation.
> So in TC-only mode the type checker vouches for the reference, but the
> generated bytecode still performs a dynamic property lookup on the enclosing
> class, which fails at runtime. {{Groovy8444.groovy}} only exercises
> {{@CompileStatic}}, so no test caught the regression.
> h3. Possible fixes
> * Apply the enum-case rewrite after STC visitation for type-checked (non-SC)
> code as well, restoring the 3.x/early-4.x behaviour (originally implemented as
> a {{CompilationUnit}} phase operation keyed off STC metadata); or
> * Have {{EnumTypeCheckingExtension}} decline to resolve the constant outside
> static compilation, so TC code at least fails at compile time (matching the
> 2.x behaviour) rather than at runtime.
> Either way, {{Groovy8444.groovy}} should gain {{@TypeChecked}} variants of the
> switch statement and switch expression tests.
> h3. Workarounds
> Qualify the constant ({{case Color.GREEN:}}), add
> {{import static Color.*}}, or use {{@CompileStatic}}.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)