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

Groovy fails to select overloaded method with vargs

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.5
    • Component/s: None
    • Labels:
      None

      Description

      the following script fails

      def mymethod(Map kwargs=[:], arg1, arg2, Object[] args) {
          println "arg1: $arg1, arg2: $arg2, args: $args, kwargs: $kwargs"
      }
      
      mymethod('hello', 'world')
      mymethod('hello', 'world', 'from', 'list')
      mymethod('hello', 'world', 'from', 'list', from: 'kwargs')
      mymethod('hello', 'world', from: 'kwargs')
      

      the reason is that the optional map will cause the generation of two methods mymethod and each of these has a vargs argument. Groovy then somehow deselects both of them instead of choosing the most specific method. Code as this might be rarely used, but it should work

        Attachments

          Activity

            People

            • Assignee:
              blackdrag Jochen Theodorou
              Reporter:
              blackdrag Jochen Theodorou
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: