[
https://issues.apache.org/jira/browse/GROOVY-12662?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18137499#comment-18137499
]
ASF GitHub Bot commented on GROOVY-12662:
-----------------------------------------
testlens-app[bot] commented on PR #3183:
URL: https://github.com/apache/groovy/pull/3183#issuecomment-6612258981
## ✅ All tests passed ✅
🏷️ Commit: 1830b63e1c0afff5ed1e25dc8f6bf5b6e85231fc
▶️ Tests: 127505 executed
⚪️ Checks: 26/26 completed
---
_Learn more about TestLens at
[testlens.app/docs](https://testlens.app/docs/features/pr-comment/)._
> STC rejects an implicit-this call in a closure to an overloaded Closure
> method, such as curry(x), as ambiguous, and ignores argument types when
> choosing the Closure method
> ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>
> Key: GROOVY-12662
> URL: https://issues.apache.org/jira/browse/GROOVY-12662
> Project: Groovy
> Issue Type: Bug
> Affects Versions: 4.0.33, 5.0.8, 7.0.0-alpha-1, 6.0.0
> Reporter: Scott Murphy Heiberg
> Priority: Major
>
> {code:groovy}
> @groovy.transform.TypeChecked // or @CompileStatic
> def test() {
> Closure<Object> c = { String a, String b -> b == null ? curry(a) : a + b }
> ((Closure) c('x', null))('y')
> }
> assert test() == 'xy'
> {code}
> *Actual:*
> {noformat}
> [Static type checking] - Reference to method is ambiguous. Cannot choose
> between [groovy.lang.Closure<V>
> groovy.lang.Closure#curry(java.lang.Object[]), groovy.lang.Closure<V>
> groovy.lang.Closure#curry(java.lang.Object)]
> {noformat}
> *Expected:* 'xy', as in dynamic Groovy, which calls curry(Object) on the
> enclosing closure. rcurry, ncurry, trampoline(), andThenSelf(), composeSelf()
> and leftShift(Closure) fail the same way.
> The selection ignores argument types altogether. If the owner declares
> memoize(String) or getDelegate(int), then memoize('x') or getDelegate(1)
> inside a closure is bound to Closure.memoize() or Closure.getDelegate().
> Under @CompileStatic the closure's method is called. Under @TypeChecked the
> inferred type is wrong, and the call fails with a GroovyCastException.
> Dynamic Groovy calls the owner's method. Under DELEGATE_ONLY,
> ClosureMetaClass sends curry, ncurry, rcurry, leftShift and rightShift to the
> delegate, but the type checker binds them to the closure.
> Cause: for an implicit-this call in a closure, StaticTypeCheckingVisitor
> takes every Closure method of that name (GROOVY-11386) without choosing among
> them by argument type, and never falls back to the delegate or owner when
> none of them accepts the arguments.
> Verified: 4.0.33 (ambiguity only), 5.0.8, 6.0.0 and master.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)