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

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

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

   ## 🚨 TestLens detected 1 failed test 🚨
   
   ### Test Summary
   > [!TIP]
   > Inspect all details with the [TestLens 
CLI](https://testlens.app/docs/features/cli): `testlens pr 3350`
   
   #### [Build and test / lts \(21, 
ubuntu-latest\)](https://github.com/apache/groovy/actions/runs/45176422276/job/137701434405?pr=3350)
 > :groovy-ant:test
   
   | Test | Runs | Flakiness |
   |---|---|--:|
   | GroovyTest > testGroovyCodeExternalURLResource | ❌ | 0% 🟢 |
   
   🏷️ Commit: 343e77edb63b844ed66bf837e83fc94135406b00
   ▶️ Tests:  1026 executed
   🟡 Checks: 5/24 completed
   
   ### Test Failures
   
   <details><summary><strong>GroovyTest > 
testGroovyCodeExternalURLResource</strong> (:groovy-ant:test in <a 
href="https://github.com/apache/groovy/actions/runs/45176422276/job/137701434405?pr=3350";>Build
 and test / lts (21, ubuntu-latest)</a>)</summary>
   
   ```
   
/home/runner/work/groovy/groovy/subprojects/groovy-ant/src/test-resources/org/codehaus/groovy/ant/GroovyTest.xml:65:
 Source resource does not exist!
        at org.codehaus.groovy.ant.Groovy.execute(Groovy.java:386)
        at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:299)
        at 
java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
        at java.base/java.lang.reflect.Method.invoke(Method.java:580)
        at 
org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:99)
        at org.apache.tools.ant.Task.perform(Task.java:350)
        at org.apache.tools.ant.Target.execute(Target.java:449)
        at org.apache.tools.ant.Target.performTasks(Target.java:470)
        at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1406)
        at org.apache.tools.ant.Project.executeTarget(Project.java:1379)
        at 
org.codehaus.groovy.ant.GroovyTest.testGroovyCodeExternalURLResource(GroovyTest.java:114)
   ```
   
   </details>
   
   ### Rerun Controls
   > [!NOTE]
   > Checks are currently running using the configuration below.
   
   Select tests to mute in this pull request:
   
   🔲 GroovyTest > testGroovyCodeExternalURLResource <!

> SC: a delegate method or property used in a lambda inside a closure throws 
> ClassCastException
> ---------------------------------------------------------------------------------------------
>
>                 Key: GROOVY-12827
>                 URL: https://issues.apache.org/jira/browse/GROOVY-12827
>             Project: Groovy
>          Issue Type: Bug
>    Affects Versions: 5.1.3, 6.0.0
>            Reporter: Paul King
>            Priority: Major
>              Labels: breaking
>
> Under \{{@CompileStatic}}, a native lambda inside a closure can compile an 
> implicit call to a method or property of the closure's delegate, but the call 
> fails at run time. Dynamic Groovy runs the same code correctly.
> {code:groovy}
> import java.util.function.Supplier
> class D {
>     String hi() \{ 'hi from D' }
> }
> @groovy.transform.CompileStatic
> class C {
>     def m() {
>         new D().with {
>             Supplier<String> s = () -> hi()
>             s.get()
>         }
>     }
> }
> assert new C().m() == 'hi from D'
> {code}
> Actual result:
> {noformat}
> java.lang.ClassCastException: class C cannot be cast to class 
> groovy.lang.Closure
> {noformat}
> h3. Cause
> The type checker records a receiver path through the enclosing closure, such 
> as \{{owner.delegate}}. The owner of a native lambda is the enclosing 
> instance rather than that closure, so the path cannot be followed at run time.
> h3. Proposed fix
> A lambda that resolves a name through the enclosing closure captures that 
> closure. The name then resolves as it would directly in the closure, 
> honouring the resolve strategy and the delegate at call time, including a 
> later \{{setDelegate}}. The lambda's own \{{owner}}, \{{delegate}} and 
> \{{thisObject}} remain the enclosing instance. Other lambdas keep their 
> current shape.
> A serializable lambda that captures the closure is generated as a 
> \{{ConvertedClosure}} proxy, as in dynamic Groovy. The JDK's 
> \{{SerializedLambda}} is replaced only after its captured values are read, so 
> a delegate that refers back to the lambda would otherwise receive the 
> \{{SerializedLambda}} and fail on deserialization. A functional interface 
> that is or implements a trait still uses the metafactory, so this 
> deserialization failure remains possible there.
> h3. Compatibility
> These affect only a serializable lambda containing such a delegate reference. 
> The reference could not run successfully before.
> * If the closure's delegate, or another value held by the closure, is not 
> serializable, writing the lambda now throws \{{NotSerializableException}}, 
> even if the delegate call is on a branch that never runs. Dynamic Groovy 
> behaves the same way.
> * An undeclared checked exception thrown from the lambda now reaches the 
> caller as \{{UndeclaredThrowableException}}. Dynamic Groovy behaves the same 
> way.
> h3. Known limitation
> A map-key property on a \{{Map}} delegate still fails with 
> \{{MissingPropertyException}}, because it is resolved dynamically and has no 
> receiver path:
> {code:groovy}
> [a: 'A'].with {
>     Supplier<String> s = () -> a
>     s.get()
> }
> {code}



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

Reply via email to