[
https://issues.apache.org/jira/browse/GROOVY-11983?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18077866#comment-18077866
]
ASF GitHub Bot commented on GROOVY-11983:
-----------------------------------------
codecov-commenter commented on PR #2509:
URL: https://github.com/apache/groovy/pull/2509#issuecomment-4365157623
##
[Codecov](https://app.codecov.io/gh/apache/groovy/pull/2509?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 `70.00000%` with `6 lines` in your changes missing
coverage. Please review.
:white_check_mark: Project coverage is 67.3271%. Comparing base
([`88ca738`](https://app.codecov.io/gh/apache/groovy/commit/88ca738c8940882e7c878c114d173255b81f7fe6?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache))
to head
([`d2378e6`](https://app.codecov.io/gh/apache/groovy/commit/d2378e67270fa2d219845f97faceb0caf58c4393?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/2509?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/2509?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)
| 70.0000% | [3 Missing and 3 partials :warning:
](https://app.codecov.io/gh/apache/groovy/pull/2509?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/2509?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
```diff
@@ Coverage Diff @@
## master #2509 +/- ##
==================================================
+ Coverage 67.3235% 67.3271% +0.0036%
- Complexity 32253 32266 +13
==================================================
Files 1490 1490
Lines 125044 125061 +17
Branches 22505 22518 +13
==================================================
+ Hits 84184 84200 +16
+ Misses 33535 33534 -1
- Partials 7325 7327 +2
```
| [Files with missing
lines](https://app.codecov.io/gh/apache/groovy/pull/2509?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/2509?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.3993% <70.0000%> (-0.1007%)` | :arrow_down: |
... and [3 files with indirect coverage
changes](https://app.codecov.io/gh/apache/groovy/pull/2509/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: unsound smart-cast in else branch of if (cond && !(x instanceof Y))
> ------------------------------------------------------------------------
>
> Key: GROOVY-11983
> URL: https://issues.apache.org/jira/browse/GROOVY-11983
> Project: Groovy
> Issue Type: Bug
> Affects Versions: 5.0.5
> Reporter: Paul King
> Assignee: Paul King
> Priority: Major
>
> {{@CompileStatic}} unsoundly smart-casts a variable in the {{else}} branch
> when the {{if}} condition has the shape {{cond && !(x instanceof Y)}}. The
> else block is reached whenever {{cond}} is false (regardless of {{x}}'s
> type), but STC narrows {{x}} to {{Y}} and codegen emits {{checkcast Y}},
> throwing {{ClassCastException}} at runtime.
> h3. Reproducer
> {code:groovy}
> import groovy.transform.CompileStatic
> abstract class Animal { String name; boolean tame }
> class Cat extends Animal {}
> @CompileStatic
> class Tester {
> static String describe(Animal a) {
> if (a.tame && !(a instanceof Cat)) {
> return "tame non-cat $a.name"
> } else {
> return "other $a.name" // <-- a smart-cast to Cat here
> }
> }
> }
> Animal mystery = new Animal() {{ name = 'x'; tame = false }}
> Tester.describe(mystery) // ClassCastException: ... cannot be cast to Cat
> {code}
> {{javap}} of {{describe}} shows {{checkcast Cat}} on {{a}} in the else block
> before {{getName()}}.
> h3. Expected
> The else branch should not narrow {{a}} to {{Cat}}: it is reached when
> {{!a.tame || a instanceof Cat}}, so {{a}} is not guaranteed to be a {{Cat}}.
> h3. Workarounds
> * Replace {{!(x instanceof Y)}} with {{!Y.isAssignableFrom(x.getClass())}}
> * Split the conditional so the {{!instanceof}} stands alone
> h3. Root cause
> {{StaticTypeCheckingVisitor.visitIfElse}} inverts captured tti entries with
> {{tti.forEach(this::putNotInstanceOfTypeInfo)}}. The inversion is
> structurally blind: a {{!instanceof}} entry contributed by one operand of
> {{&&}} is unwrapped into the positive smart-cast bucket for the else branch,
> even though the else does not imply that operand was false. Sound for a
> single-operand boolean; unsound for compound conditions mixing {{&&}} with
> {{!instanceof}}.
> Related: GROOVY-6429, GROOVY-8412, GROOVY-8523, GROOVY-9931, GROOVY-11864
> (same {{tti}} plumbing); GROOVY-7971 fixed the symmetric then-branch issue
> for {{||}}.
> h3. Affects
> Groovy 5.0.x and 6.0.0-SNAPSHOT (master). Not present in 4.0.x.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)