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

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

testlens-app[bot] commented on PR #3091:
URL: https://github.com/apache/groovy/pull/3091#issuecomment-6536937950

   ## 🚨 TestLens detected 1 failed test 🚨
   
   ### Test Summary
   > [!TIP]
   > Inspect all details with the [TestLens 
CLI](https://testlens.app/docs/features/cli): `testlens pr 3091`
   
   #### [Build and test / lts \(21, 
ubuntu-latest\)](https://github.com/apache/groovy/actions/runs/41151302009/job/124388210944?pr=3091)
 > :test
   
   | Test | Runs | Flakiness |
   |---|---|--:|
   | MethodReferenceTest > 
testMethodReferencesInStaticAndDefaultMethodsOfInterface\(\) | ❌ | 0% 🟢 |
   
   🏷️ Commit: 72f4f923244fafd5e219122060d493f694ddff89
   ▶️ Tests:  70522 executed
   🟡 Checks: 14/24 completed
   
   ### Test Failures
   
   <details><summary><strong>MethodReferenceTest > 
testMethodReferencesInStaticAndDefaultMethodsOfInterface()</strong> (:test in 
<a 
href="https://github.com/apache/groovy/actions/runs/41151302009/job/124388210944?pr=3091";>Build
 and test / lts (21, ubuntu-latest)</a>)</summary>
   
   ```
   java.lang.ClassFormatError: Method gstring$I$ctorRef$make$0$1 in class I has 
illegal modifiers: 0x101A
        at java.base/java.lang.ClassLoader.defineClass1(Native Method)
        at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1027)
        at 
java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:150)
        at groovy.lang.GroovyClassLoader.access$000(GroovyClassLoader.java:90)
        at 
groovy.lang.GroovyClassLoader$ClassCollector.createClass(GroovyClassLoader.java:1305)
        at groovy.lang.GroovyClassLoader.collect(GroovyClassLoader.java:284)
        at 
groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:440)
        at 
groovy.lang.GroovyClassLoader.lambda$parseClass$2(GroovyClassLoader.java:378)
        at 
org.codehaus.groovy.runtime.memoize.ConcurrentCommonCache.getAndPut(ConcurrentCommonCache.java:143)
        at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:378)
        at groovy.lang.GroovyShell.parseClass(GroovyShell.java:664)
        at groovy.lang.GroovyShell.parse(GroovyShell.java:677)
        at groovy.lang.GroovyShell.parse(GroovyShell.java:689)
        at groovy.lang.GroovyShell.evaluate(GroovyShell.java:551)
        at groovy.lang.GroovyShell.evaluate(GroovyShell.java:587)
        at groovy.lang.GroovyShell.evaluate(GroovyShell.java:571)
        at groovy.test.GroovyAssert.assertScript(GroovyAssert.java:107)
        at 
groovy.transform.stc.MethodReferenceTest.testMethodReferencesInStaticAndDefaultMethodsOfInterface(MethodReferenceTest.groovy:1613)
   ```
   
   </details>
   
   ### Rerun Controls
   > [!NOTE]
   > Checks are currently running using the configuration below.
   
   Select tests to mute in this pull request:
   
   🔲 MethodReferenceTest > 
testMethodReferencesInStaticAndDefaultMethodsOfInterface\(\) <!

> STC: instanceof narrows a variable where the check does not guard the code
> --------------------------------------------------------------------------
>
>                 Key: GROOVY-12562
>                 URL: https://issues.apache.org/jira/browse/GROOVY-12562
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static Type Checker
>    Affects Versions: 4.0.33, 5.0.8, 6.0.0
>            Reporter: Scott Murphy Heiberg
>            Priority: Major
>
> The type checker narrows a variable after any {{instanceof}} check on it, for 
> the rest of the expression or statement, wherever the check is. Under 
> {{@CompileStatic}} the program then fails with a ClassCastException:
> {code:groovy}
> @groovy.transform.CompileStatic
> String f(CharSequence cs) { 'x' + (cs instanceof String) + cs.length() }
> f(new StringBuilder('ab')) // ClassCastException: StringBuilder cannot be 
> cast to String (5.0.8, 6.0.0)
> {code}
> The same holds for {{foo(cs instanceof String, cs.length())}}, {{[cs 
> instanceof String, cs]}} and {{(cs instanceof String) == cs.isEmpty()}}. A 
> comparison with {{false}} narrows the wrong branch, and the condition of a 
> loop narrows after the loop:
> {code:groovy}
> @groovy.transform.CompileStatic
> int h(Object x) { if ((x instanceof String) == false) { return x.length() }; 
> 0 }
> h(42) // ClassCastException: Integer cannot be cast to String
> @groovy.transform.CompileStatic
> int g(Object x) { while (x instanceof String) { break }; x.length() }
> g(42) // ClassCastException
> {code}
> The last two fail in 4.0.33, 5.0.8 and 6.0.0, the first in 5.0.8 and 6.0.0.
> Expected: a check narrows only where its outcome guards what follows (the 
> condition of an if, while, for, assert or conditional expression, and 
> operands of &&, || and ! there); {{(x instanceof T) == true}} narrows like 
> the check and {{== false}} like its negation; a loop condition narrows inside 
> the loop only.
> Behaviour change under @TypeChecked and @CompileStatic: an instanceof check 
> now narrows the variable only where its outcome guards the code (conditions, 
> operands of &&, || and !, comparisons with a boolean literal, boolean casts, 
> assignments in a condition), and the condition of a loop narrows inside the 
> loop only. Code that relied on the old narrowing compiled before and is now a 
> compile error, for example
> {code:groovy}
> @CompileStatic
> def f(Object x) { '' + (x instanceof String) + x.length() }
> // before: compiled; f(new StringBuilder('ab')) threw ClassCastException
> // now: [Static type checking] - Cannot find matching method 
> java.lang.Object#length()
> {code}
> and likewise a call of {{x.length()}} after a {{while (x instanceof String)}} 
> loop. A check that is a statement on its own did not narrow later statements 
> before and does not now; switch/case and catch are unaffected. The PR adds a 
> COMPATIBILITY.md entry.
> PR: https://github.com/apache/groovy/pull/3091



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to