[
https://issues.apache.org/jira/browse/GROOVY-12672?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18137532#comment-18137532
]
ASF GitHub Bot commented on GROOVY-12672:
-----------------------------------------
testlens-app[bot] commented on PR #3193:
URL: https://github.com/apache/groovy/pull/3193#issuecomment-6613512380
## ✅ All tests passed ✅
🏷️ Commit: b1bd8dcfcbcbb8f883b82b85a3f44112536c99a5
▶️ Tests: 123771 executed
⚪️ Checks: 26/26 completed
---
_Learn more about TestLens at
[testlens.app/docs](https://testlens.app/docs/features/pr-comment/)._
> SC: a lambda that reads delegate, owner, resolveStrategy or
> maximumNumberOfParameters throws ClassCastException
> ---------------------------------------------------------------------------------------------------------------
>
> Key: GROOVY-12672
> URL: https://issues.apache.org/jira/browse/GROOVY-12672
> Project: Groovy
> Issue Type: Bug
> Affects Versions: 7.0.0-alpha-1, 6.0.0
> Reporter: Scott Murphy Heiberg
> Priority: Major
>
> {code:groovy}
> import groovy.transform.CompileStatic
> import java.util.function.Supplier
> @CompileStatic
> class C {
> def m() {
> Supplier<Object> s = () -> delegate
> s.get()
> }
> }
> assert new C().m() instanceof C
> {code}
> *Actual:* {{java.lang.ClassCastException: class java.lang.Class cannot be
> cast to class C$_m_lambda1}}. The same happens for {{owner}},
> {{maximumNumberOfParameters}}, {{resolveStrategy}}, {{parameterTypes}},
> {{directive}} and {{metaClass}}, in instance and static methods, in nested
> lambdas and in a lambda inside a closure. Assigning {{resolveStrategy}} fails
> with {{NoSuchMethodException: java.lang.Class.setProperty}}.
> *Expected:* the property is read from the lambda. {{delegate}} and {{owner}}
> are the enclosing object, as for {{thisObject}} and as the type checker
> infers; in a static method they are the class. 4.0.33 and 5.0.8 do not throw;
> they return the class for {{delegate}} and {{owner}}.
> Cause: since GROOVY-11905, a lambda that does not touch the enclosing
> instance gets a static {{doCall}}. Only {{this}}, {{super}} and
> {{thisObject}} counted as such access ({{StaticTypesLambdaAnalyzer}}), so a
> closure property is read from the enclosing Class instead of the lambda.
> Verified: 6.0.0 and master affected; 4.0.33 and 5.0.8 not affected.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)