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

vararg method resolution with static compilation selects wrong candidate between (String...) and (Class<?> ...)

    XMLWordPrintableJSON

Details

    Description

      As discussed here:
      http://groovy.329449.n5.nabble.com/CompileStatic-breaking-vararg-call-resolution-td5718966.html
      There seem to be at least two bug-like symptoms when using @CompileStatic, for resolving Constructors and for resolving methods.
      ```
      import groovy.transform.CompileStatic

      @CompileStatic
      public class Starter {
      public static void main(String[] args)

      { new Starter(List.class, Map.class) //println foo (List.class, Map.class) }

      public Starter(Class<?>... classes)

      {System.out.println("Classes");}

      public Starter(String... strings)

      {System.out.println("Strings");}

      static def foo(Class... cs)

      { "Classes" }

      static def foo(String... ss)

      { "Strings" }

      }
      ```

      When run like this, prints "Strings", should print "Classes" as it does without @CompileStatic.
      When commenting out the call to foo, Should print "Classes", "Classes", instead currently does not compile:
      ```
      org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
      /tmp/Starter.groovy: 8: [Static type checking] - Cannot call Starter#foo(java.lang.String[]) with arguments [java.lang.Class <java.util.List>, java.lang.Class <java.util.Map>]
      @ line 8, column 9.
      foo (List.class, Map.class)
      ```

      Attachments

        Activity

          People

            blackdrag Jochen Theodorou
            tkruse Thibault Kruse
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: