[
https://issues.apache.org/jira/browse/GROOVY-12679?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18137647#comment-18137647
]
ASF GitHub Bot commented on GROOVY-12679:
-----------------------------------------
testlens-app[bot] commented on PR #3200:
URL: https://github.com/apache/groovy/pull/3200#issuecomment-6618115923
## ✅ All tests passed ✅
🏷️ Commit: a170fa5b3211754fd3a35d4e4a6b4de82a0494dd
▶️ Tests: 116257 executed
⚪️ Checks: 27/27 completed
---
_Learn more about TestLens at
[testlens.app/docs](https://testlens.app/docs/features/pr-comment/)._
> Closures from AsyncClosureUtils.wrapAsync/wrapAsyncGenerator ignore the
> delegate and resolve strategy and misreport their parameters
> ------------------------------------------------------------------------------------------------------------------------------------
>
> Key: GROOVY-12679
> URL: https://issues.apache.org/jira/browse/GROOVY-12679
> Project: Groovy
> Issue Type: Bug
> Affects Versions: 6.0.0
> Reporter: Scott Murphy Heiberg
> Priority: Major
>
> {code:groovy}
> import org.apache.groovy.runtime.async.AsyncClosureUtils
> class Ctx { String greet() { 'hi' } }
> Closure wrapped = AsyncClosureUtils.wrapAsync { -> greet() }
> wrapped.delegate = new Ctx()
> wrapped.resolveStrategy = Closure.DELEGATE_FIRST
> assert await(wrapped()) == 'hi'
> assert await(new Ctx().with(AsyncClosureUtils.wrapAsync { greet() })) == 'hi'
> def w = AsyncClosureUtils.wrapAsync { String k, Integer v -> k * v }
> assert w.maximumNumberOfParameters == 2
> assert [a: 1, b: 2].collect(w).collect { await(it) } == ['a', 'bb']
> {code}
> *Actual:* MissingMethodException: No signature of method: greet for class:
> Script1. After setting a delegate on the wrapper, getDelegate() still returns
> the script and getResolveStrategy() returns OWNER_FIRST. If the wrapped
> closure is configured instead, the wrapper reports its own owner and
> OWNER_FIRST. The wrapper reports one Object[] parameter, so Map.collect
> passes the entry to a two-parameter closure and fails with
> MissingMethodException: doCall ... (Entry). wrapAsyncGenerator behaves the
> same.
> *Expected:* the same behaviour as calling the wrapped closure directly: names
> resolve against the delegate, with(), dehydrate() and rehydrate() work, and
> the wrapped closure's parameters are reported.
> Cause: the wrappers are anonymous Closure subclasses that copy only the owner
> and this object of the wrapped closure. They keep their own delegate and
> resolve strategy, which the wrapped closure never sees, and report the
> parameters of their own doCall(Object...).
> Verified on 6.0.0 and master (the API is new in 6.0.0).
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)