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

About the number of arguments in calling methods

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.0-beta-10, 1.0-JSR-1, 1.0-JSR-2
    • 1.0-JSR-4
    • None
    • None

    Description

      I have test the following script, named as argumentsTest.groovy, on several groovy releases and CVS Head.
      ------------------------------------------
      def fn(a, b, c, d) {
      return a + b + c + d
      }

      println fn(1, 2, 3, 4)
      println fn([1, 2, 3, 4]) // Expected fail
      println fn([1, 2, 3]) // Expected fail

      Executed on Groovy-1.0-JSR-03-SNAPSHOT (CVS HEAD)
      ------------------------------------------------------
      10
      10
      Caught: groovy.lang.GroovyRuntimeException: failed to invoke method: groovy.lang
      .MetaClass$3@1ec8909[name: fn params: [class java.lang.Object, class java.lang.O
      bject, class java.lang.Object, class java.lang.Object] returns: class java.lang.
      Object owner: class argumentsTest] on: argumentsTest@1b48197 with arguments: [[1
      , 2, 3]]reason: java.lang.IllegalArgumentException: wrong number of arguments

      Executed on Groovy-1.0-JSR-02
      -------------------------------------------
      10
      [1, 2, 3, 4, null, null, null]
      [1, 2, 3, null, null, null]

      Executed on Groovy-1.0-JSR-01
      -------------------------------------------
      10
      10
      Caught: groovy.lang.GroovyRuntimeException: failed to invoke method: groovy.lang
      .MetaClass$2@e6ff0d[name: fn params: [class java.lang.Object, class java.lang.Ob
      ject, class java.lang.Object, class java.lang.Object] returns: class java.lang.O
      bject owner: class argumentsTest] on: argumentsTest@b9b538 with arguments: [[1,
      2, 3]]reason: java.lang.IllegalArgumentException: wrong number of arguments
      ................................................
      ................................................

      Executed on Groovy-1.0-Beta-10
      -------------------------------------
      10
      10
      Caught: groovy.lang.GroovyRuntimeException: failed to invoke method: groovy.lang
      .MetaClass$3@1ec8909[name: fn params: [class java.lang.Object, class java.lang.O
      bject, class java.lang.Object, class java.lang.Object] returns: class java.lang.
      Object owner: class argumentsTest] on: argumentsTest@1b48197 with arguments: [[1
      , 2, 3]]reason: java.lang.IllegalArgumentException: wrong number of arguments

      Attachments

        Activity

          People

            blackdrag Jochen Theodorou
            phkim Kim, Pilho
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: