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

Support true optional parameters.

    XMLWordPrintableJSON

Details

    • New Feature
    • Status: Closed
    • Major
    • Resolution: Duplicate
    • 1.6.2
    • None
    • None
    • None

    Description

      Currently, there is no way of calling a method with sparse optional parameters that are not sequential with respect to the order in which the parameters are declared.

      Python offers this flexibility, and it makes sense that Groovy allow it, too. When implemented, the following would be expected to pass:

      public def foo(int a, int b = 42, int c = 314)
      {
          return [a, b, c]
      }
      
      // the following two cases pass, atm.
      assert foo(1) == [1, 42, 314]
      assert foo(1, 2) == [1, 2, 314]
      // the following three cases fail, atm.
      assert foo(1, b: 2) == [1, 2, 314]
      assert foo(1, c: 3) == [1, 42, 3]
      assert foo(1, b: 2, c: 3) == [1, 2, 3]
      

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              sukhyun.cho sukhyun.cho
              Votes:
              3 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: