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

Groovy fails to select overloaded method with vargs

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • None
    • 1.5
    • None
    • 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

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

            Dates

              Created:
              Updated:
              Resolved: