[
https://issues.apache.org/jira/browse/GROOVY-12397?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18113853#comment-18113853
]
ASF GitHub Bot commented on GROOVY-12397:
-----------------------------------------
codecov-commenter commented on PR #2920:
URL: https://github.com/apache/groovy/pull/2920#issuecomment-5619552679
##
[Codecov](https://app.codecov.io/gh/apache/groovy/pull/2920?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 `93.75000%` with `2 lines` in your changes missing
coverage. Please review.
:white_check_mark: Project coverage is 71.2094%. Comparing base
([`c52e9f7`](https://app.codecov.io/gh/apache/groovy/commit/c52e9f76d03193549a4873a8b289988cca38202f?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache))
to head
([`7a67893`](https://app.codecov.io/gh/apache/groovy/commit/7a67893c44338e1427d9b9f5915f30cb42f90301?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
:warning: Report is 6 commits behind head on master.
| [Files with missing
lines](https://app.codecov.io/gh/apache/groovy/pull/2920?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/classgen/asm/BinaryExpressionHelper.java](https://app.codecov.io/gh/apache/groovy/pull/2920?src=pr&el=tree&filepath=src%2Fmain%2Fjava%2Forg%2Fcodehaus%2Fgroovy%2Fclassgen%2Fasm%2FBinaryExpressionHelper.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3JjL21haW4vamF2YS9vcmcvY29kZWhhdXMvZ3Jvb3Z5L2NsYXNzZ2VuL2FzbS9CaW5hcnlFeHByZXNzaW9uSGVscGVyLmphdmE=)
| 90.0000% | [0 Missing and 2 partials :warning:
](https://app.codecov.io/gh/apache/groovy/pull/2920?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/2920?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
```diff
@@ Coverage Diff @@
## master #2920 +/- ##
==================================================
+ Coverage 71.2002% 71.2094% +0.0092%
- Complexity 37714 37727 +13
==================================================
Files 1584 1584
Lines 136463 136489 +26
Branches 25353 25358 +5
==================================================
+ Hits 97162 97193 +31
+ Misses 30540 30536 -4
+ Partials 8761 8760 -1
```
| [Files with missing
lines](https://app.codecov.io/gh/apache/groovy/pull/2920?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
| Coverage Δ | |
|---|---|---|
|
[...codehaus/groovy/classgen/VariableScopeVisitor.java](https://app.codecov.io/gh/apache/groovy/pull/2920?src=pr&el=tree&filepath=src%2Fmain%2Fjava%2Forg%2Fcodehaus%2Fgroovy%2Fclassgen%2FVariableScopeVisitor.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3JjL21haW4vamF2YS9vcmcvY29kZWhhdXMvZ3Jvb3Z5L2NsYXNzZ2VuL1ZhcmlhYmxlU2NvcGVWaXNpdG9yLmphdmE=)
| `94.1781% <100.0000%> (ø)` | |
|
[...org/codehaus/groovy/classgen/asm/CompileStack.java](https://app.codecov.io/gh/apache/groovy/pull/2920?src=pr&el=tree&filepath=src%2Fmain%2Fjava%2Forg%2Fcodehaus%2Fgroovy%2Fclassgen%2Fasm%2FCompileStack.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3JjL21haW4vamF2YS9vcmcvY29kZWhhdXMvZ3Jvb3Z5L2NsYXNzZ2VuL2FzbS9Db21waWxlU3RhY2suamF2YQ==)
| `84.8723% <100.0000%> (+0.4412%)` | :arrow_up: |
|
[.../codehaus/groovy/classgen/asm/StatementWriter.java](https://app.codecov.io/gh/apache/groovy/pull/2920?src=pr&el=tree&filepath=src%2Fmain%2Fjava%2Forg%2Fcodehaus%2Fgroovy%2Fclassgen%2Fasm%2FStatementWriter.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3JjL21haW4vamF2YS9vcmcvY29kZWhhdXMvZ3Jvb3Z5L2NsYXNzZ2VuL2FzbS9TdGF0ZW1lbnRXcml0ZXIuamF2YQ==)
| `98.3982% <100.0000%> (ø)` | |
|
[...us/groovy/classgen/asm/BinaryExpressionHelper.java](https://app.codecov.io/gh/apache/groovy/pull/2920?src=pr&el=tree&filepath=src%2Fmain%2Fjava%2Forg%2Fcodehaus%2Fgroovy%2Fclassgen%2Fasm%2FBinaryExpressionHelper.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3JjL21haW4vamF2YS9vcmcvY29kZWhhdXMvZ3Jvb3Z5L2NsYXNzZ2VuL2FzbS9CaW5hcnlFeHByZXNzaW9uSGVscGVyLmphdmE=)
| `89.1892% <90.0000%> (-0.0075%)` | :arrow_down: |
... and [7 files with indirect coverage
changes](https://app.codecov.io/gh/apache/groovy/pull/2920/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>
> VerifyError for a pattern variable bound in a later &&/|| operand (JEP 394
> flow scoping)
> ----------------------------------------------------------------------------------------
>
> Key: GROOVY-12397
> URL: https://issues.apache.org/jira/browse/GROOVY-12397
> Project: Groovy
> Issue Type: Bug
> Affects Versions: 6.0.0-RC-1
> Reporter: Paul King
> Assignee: Paul King
> Priority: Major
>
> Two related problems with JEP 394 {{instanceof}} pattern variables
> (GROOVY-12242), present in 6.0.0-RC-1.
> h3. 1. VerifyError for a pattern variable bound in a later {{&&}} / {{||}}
> operand
> A pattern variable declared in the right operand of {{&&}} or {{||}} has its
> slot allocated and null-initialised only at its own {{instanceof}} site. That
> operand is skipped when the left operand decides the result, so at the join
> the slot is undefined on one path and any later read of it (a following
> conjunct, the then branch) fails bytecode verification:
> {code:groovy}
> def trimmed(Object p) {
> if (p instanceof String s && s.length() > 0 && s.trim() instanceof String
> t) {
> return t
> }
> return null
> }
> trimmed(' ab ')
> {code}
> {noformat}
> java.lang.VerifyError: Bad local variable type
> {noformat}
> The same happens with {{||}}:
> {code:groovy}
> if (!(p instanceof String s) || s.isEmpty() || !(s.trim() instanceof String
> t)) return null
> return t
> {code}
> h3. 2. A pattern binding does not survive an if arm ending in {{break}} or
> {{continue}}
> JLS §14.22 says {{break}} and {{continue}} cannot complete normally, so per
> §6.3.2.2-200-C the other path's bindings are in scope after the {{if}}.
> {{VariableScopeVisitor}} and the if-statement writer only recognised
> {{return}}, {{throw}} and {{yield}}:
> {code:groovy}
> def upper(List items) {
> def out = []
> for (o in items) {
> if (!(o instanceof String s)) continue
> out << s.toUpperCase()
> }
> out
> }
> upper(['a', 1, 'b'])
> {code}
> {noformat}
> groovy.lang.MissingPropertyException: No such property: s for class: Script1
> {noformat}
> h3. Fix
> * {{BinaryExpressionHelper}} pre-declares the pattern variables of the right
> operand of {{&&}} / {{||}} before the left operand runs; the {{instanceof}}
> site reuses the pre-declared slot ({{CompileStack}} keeps the set).
> * {{VariableScopeVisitor}} and {{StatementWriter.writeIfElse}} use
> {{mayCompleteNormally}} for the "arm is abrupt" test, so {{break}} and
> {{continue}} count.
> Reproducer script covering all four cases (on 6.0.0-RC-1 it reports two
> VerifyErrors and two MissingPropertyExceptions):
> {code:groovy}
> // Save as patternSlots.groovy and run: groovy patternSlots.groovy
> def cases = [
> 'pattern variable bound in a later && operand': '''
> def trimmed(Object p) {
> if (p instanceof String s && s.length() > 0 && s.trim()
> instanceof String t) {
> return t
> }
> return null
> }
> assert trimmed(' ab ') == 'ab'
> assert trimmed('') == null
> assert trimmed(42) == null
> ''',
> 'pattern variable bound in a later || operand': '''
> def viaOr(Object p) {
> if (!(p instanceof String s) || s.isEmpty() || !(s.trim()
> instanceof String t)) {
> return null
> }
> return t
> }
> assert viaOr(' cd ') == 'cd'
> assert viaOr(42) == null
> ''',
> 'binding survives an if arm ending in continue': '''
> def upper(List items) {
> def out = []
> for (o in items) {
> if (!(o instanceof String s)) continue
> out << s.toUpperCase()
> }
> out
> }
> assert upper(['a', 1, 'b']) == ['A', 'B']
> ''',
> 'binding survives an if arm ending in break': '''
> def upper(List items) {
> def out = []
> for (o in items) {
> if (o !instanceof String s) break
> out << s.toUpperCase()
> }
> out
> }
> assert upper(['a', 'b', 1, 'c']) == ['A', 'B']
> ''',
> ]
> println "Groovy ${GroovySystem.version}"
> cases.each { name, source ->
> try {
> new GroovyShell().evaluate(source)
> println "PASS $name"
> } catch (Throwable t) {
> println "FAIL $name: ${t.class.simpleName}:
> ${t.message?.readLines()?.head()}"
> }
> }
> {code}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)