Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-1967

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

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.1-beta-1
    • 1.1-beta-2
    • None
    • None

    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
      // }
      }

      Attachments

        Activity

          People

            blackdrag Jochen Theodorou
            jbaumann Joachim Baumann
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: