[
https://issues.apache.org/jira/browse/GROOVY-3351?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18149557#comment-18149557
]
ASF GitHub Bot commented on GROOVY-3351:
----------------------------------------
daniellansun opened a new pull request, #3343:
URL: https://github.com/apache/groovy/pull/3343
https://issues.apache.org/jira/browse/GROOVY-3351
Assigning a curried MethodClosure to a metaClass now registers every
overload the curry can still call, including the shorter ones default
parameters generate. Direct calls such as
`Foo.&fooWithDefaults.curry("A")("B")` already worked; `foo("B")` after a
metaClass assignment used to throw `MissingMethodException`.
`CurriedClosure.expandSignatures` drops the parameters the curry binds,
using the same insertion point as `getUncurriedArguments`. Copies of an
`rcurry` closure stay lazy, so a cloned or dehydrated right-curried closure
keeps that rule. Varargs and composed closures keep a single meta-method, as
before.
`testGroovy3351` now runs as a regular test; its assertions are unchanged.
Additional coverage is in `Groovy3351Test`.
> Curried MethodClosure with default parameters wont work
> -------------------------------------------------------
>
> Key: GROOVY-3351
> URL: https://issues.apache.org/jira/browse/GROOVY-3351
> Project: Groovy
> Issue Type: Bug
> Components: groovy-runtime
> Affects Versions: 2.4.0
> Reporter: Andres Almiray
> Assignee: Daniel Sun
> Priority: Major
>
> As detailed on this thread
> http://www.nabble.com/Curried-closures-with-default-parameters-td21906130.html
> currying a Methodclosure whose original method has default parameters and
> assigning it to a metaClass means the default parameters are lost, the
> workaround is to 'manually' curry the closure
> {code}
> class Foo {
> static fooWithDefaults( String a1, String a2, String a3 = a2, Map a4 = [:]
> ) { /*stuff*/ }
> static decorate( Class klass ) {
> klass.metaclass.foo = this.&fooWithDefaults.curry("A")
> }
> }
> def f = new Foo()
> f.foo("B") // throws MME
> f.foo("B","C",[:]) // works
> {code}
> workaround
> {code}
> class Foo {
> static fooWithDefaults( String a1, String a2, String a3 = a2, Map a4 = [:]
> ) { /*stuff*/ }
> static decorate( Class klass ) {
> klass.metaClass.foo = { String a2, String a3 = a2, Map a4 = [:] ->
> Foo.fooWithDefaults("A",a2,a3,a4)
> }
> }
> }
> {code}
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)