groovy

When assigned to a local variable or attribute, a closure with named parameters throws a verify error

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 1.1-beta-1
  • Fix Version/s: 1.1-beta-2
  • Component/s: None
  • Labels:
    None
  • Testcase included:
    yes
  • Number of attachments :
    0

Description

When assigned to a local variable or attribute, a closure with named parameters throws a verify error.

However, if the closure is called directly upon creation (i.e. without intermediate assignment to a variable), then the call works without problems.
The same holds true if in a script the Binding is used to store the closure reference instead of a variable.

Here is a test case. The commented test methods throw the verify error.

class ClosureNamedParameters extends GroovyTestCase {

// void testClosureAsLocalVar() {
// def local = { Map params -> // params.x * params.y // }
// assert local(x : 2, y : 3) == 6
// }
void testClosureDirectly() {
assert { Map params -> params.x * params.y }(x : 2, y : 3) == 6
}
// def attribute
// void testClosureAsAttribute() {
// attribute = { Map params ->// params.x * params.y// } }
// assert attribute(x : 2, y : 3) == 6
// }
}

Activity

Hide
blackdrag blackdrag added a comment -

looks like the resulting map was not packed into a Object[] for the call.. fixed now

Show
blackdrag blackdrag added a comment - looks like the resulting map was not packed into a Object[] for the call.. fixed now

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: