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

STC Method resolution fails if other methods with more parameters exist

    XMLWordPrintableJSON

Details

    Description

      Given two classes as follows

      @groovy.transform.CompileStatic
      class A {
         public static String msg( String key, Object[] args ) { "key=$key, args=$args" }
         public static String msg( String key, Object[] args, Object[] parts ) { "key=$key, args=$args, parts=$parts" }
         public static String msg( String key, Object[] args, String[] names ) { "key=$key, args=$args, names=$names" }
      }
      

      and

      @groovy.transform.CompileStatic
      public class B {
         public static void main( String[] args ) {
            println A.msg( 'hello', [ 'world' ] as Object[] )
         }
      }
      

      will not compile with the error

      B.groovy: 4: [Static type checking] - Reference to method is ambiguous. Cannot choose between [java.lang.String A#msg(java.lang.String, java.lang.Object[], java.lang.Object[]), java.lang.String A#msg(java.lang.String, java.lang.Object[], java.lang.String[])]
       @ line 4, column 15.
               println A.msg( 'hello', [ 'world' ] as Object[] )
      

      Though there's a perfect match for the called method, it tries to choose one of the longer signatures.

      Attachments

        Activity

          People

            emilles Eric Milles
            patric42 Patric Bechtel
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: