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

Unexpected type mismatch when having overloaded methods with variable arguments

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • None
    • None
    • Static Type Checker
    • None

    Description

      I have the following program

      import java.util.function.Supplier;
      
      class Main {
        static final void test() {
          Main.<String>m(() -> "df", "fdaf");
        }
      
        static <T> void m(Supplier<T> x, T... y) {}
        static <T extends Comparable<? extends T>> void m(T...y) {}
      }
      

      Actual behavior

      org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
      test.groovy: 5: [Static type checking] - Cannot return value of type java.lang.String for lambda expecting int
       @ line 5, column 26.
             Main.<String>m(() -> "df", "fdaf");
                                  ^
      
      1 error
      

      Expected behavior

      Compile successfully

      Notes

      Tested against master (commit: a4e0d6de9cc2d8ecb48b48df501e63ec1735d837)

      Test case adapted from:

      class Main {
        static final void test() {
          org.apache.commons.lang3.ObjectUtils.<String>median((stills, impeaches) ->   86 , "fdaf");
        }
      }
      

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              theosot Thodoris Sotiropoulos
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated: