Details
Description
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
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
workaround
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)
}
}
}
Activity
blackdrag blackdrag
made changes -
| Field | Original Value | New Value |
|---|---|---|
| Fix Version/s | 1.5.8 [ 14630 ] | |
| Fix Version/s | 1.6.1 [ 14852 ] | |
| Component/s | Compiler [ 13529 ] | |
| Fix Version/s | 1.7-beta-1 [ 14014 ] |
Guillaume Laforge
made changes -
| Fix Version/s | 1.6.2 [ 15151 ] | |
| Fix Version/s | 1.6.1 [ 14852 ] |
Guillaume Laforge
made changes -
| Fix Version/s | 1.5.8 [ 14630 ] |
Guillaume Laforge
made changes -
| Fix Version/s | 1.6.3 [ 15251 ] | |
| Fix Version/s | 1.6.2 [ 15151 ] |
Guillaume Laforge
made changes -
| Fix Version/s | 1.6.3 [ 15251 ] |
Guillaume Laforge
made changes -
| Fix Version/s | 1.7-beta-x [ 15538 ] | |
| Fix Version/s | 1.7-beta-1 [ 14014 ] |
blackdrag blackdrag
made changes -
| Fix Version/s | 1.8.x [ 15750 ] | |
| Fix Version/s | 2.x [ 17013 ] | |
| Fix Version/s | 1.7.x [ 15538 ] |
Errors generated by running the 1st script