[
https://issues.apache.org/jira/browse/GROOVY-12563?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18135603#comment-18135603
]
ASF GitHub Bot commented on GROOVY-12563:
-----------------------------------------
testlens-app[bot] commented on PR #3092:
URL: https://github.com/apache/groovy/pull/3092#issuecomment-6539722812
## 🚨 All tests passed but jobs failed 🚨
### Failed Jobs without Test Failures
❌ [Build and test / lts \(17,
macos-latest\)](https://github.com/apache/groovy/actions/runs/41169505755/job/124444199056?pr=3092)
❌ [Build and test / lts \(17,
ubuntu-latest\)](https://github.com/apache/groovy/actions/runs/41169505755/job/124444199020?pr=3092)
❌ [Build and test / lts \(17, windows-latest,
1\)](https://github.com/apache/groovy/actions/runs/41169505755/job/124444198982?pr=3092)
❌ [Build and test / lts \(21,
ubuntu-latest\)](https://github.com/apache/groovy/actions/runs/41169505755/job/124444198974?pr=3092)
❌ [Build and test / lts \(25,
ubuntu-latest\)](https://github.com/apache/groovy/actions/runs/41169505755/job/124444198787?pr=3092)
🏷️ Commit: 55476c5f8b450828dd001fb9fa858a7a26b122c6
▶️ Tests: 42259 executed
⚪️ Checks: 26/26 completed
### Rerun Controls
Click the checkbox to trigger a rerun:
- [ ] **Rerun jobs**
---
_Learn more about TestLens at
[testlens.app/docs](https://testlens.app/docs/features/pr-comment/)._
> SC: closures and lambdas in a trait method see the trait helper class instead
> of the trait instance
> ---------------------------------------------------------------------------------------------------
>
> Key: GROOVY-12563
> URL: https://issues.apache.org/jira/browse/GROOVY-12563
> Project: Groovy
> Issue Type: Bug
> Components: Static compilation, Static Type Checker
> Affects Versions: 4.0.33, 5.0.8, 6.0.0
> Reporter: Scott Murphy Heiberg
> Priority: Major
>
> In a statically compiled trait method, closures and lambdas get the static
> helper class where the trait instance (or, in a static method, the
> implementing class) is expected:
> {code:groovy}
> @groovy.transform.CompileStatic
> trait T {
> String helper() { 'helper' }
> Object own() { def c = { owner }; c() }
> String viaThis() { def c = { this.helper() }; c() }
> String viaLambda() { java.util.function.Supplier<String> s = () ->
> helper(); s.get() }
> }
> @groovy.transform.CompileStatic
> class C implements T { }
> new C().own() // GroovyCastException: Cannot cast object 'C@...' with
> class 'C' to class 'T$Trait$Helper'
> new C().viaThis() // ClassCastException: class java.lang.Class cannot be
> cast to class T$Trait$Helper
> new C().viaLambda() // ClassCastException: class java.lang.Class cannot be
> cast to class T
> {code}
> Also: {{thisObject}}, {{delegate}} without {{@DelegatesTo}}, {{getOwner()}}
> and {{getThisObject()}} in such a closure (also under {{@TypeChecked}}); a
> closure written in a lambda; {{this.m()}} in a closure of a dynamic or
> {{@TypeChecked}} trait (MissingMethodException for a method with arguments,
> the helper's {{toString()}} and {{getClass()}}); and calling a static closure
> field of the trait as a method:
> {code:groovy}
> @groovy.transform.CompileStatic
> trait T {
> static Closure<String> f = { 'f' }
> static String callF() { f() }
> }
> @groovy.transform.CompileStatic
> class C implements T { }
> C.callF() // 6.0.0: MissingMethodException: No signature of static method:
> T__f$get for class: T
> // 4.0.33, 5.0.8: [Static type checking] - Cannot find matching
> method java.lang.Class#f()
> {code}
> Expected: these give the values and calls dynamic Groovy gives: the trait
> instance as this object, owner and delegate of a closure written directly in
> a trait method, the lambda as the owner of a closure written in a lambda, and
> the implementing class's static field.
> PR: https://github.com/apache/groovy/pull/3092
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)