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

unexpected error when having overloaded methods, one of which receiving an Iterable

    XMLWordPrintableJSON

Details

    Description

      I have the following program

      import java.util.function.*;
      
      class Foo<T> {
        static <T> Foo<T> of(Iterable<T> values) { return null; }
        static <T> Foo<T> of(T values) { return null; }
      }
      
      class Main {
        static final void test() {
          Foo.<IntUnaryOperator>of((int s) -> s + 1);
        }
      }
      

      Actual behavior

      org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
      Main.groovy: 10: [Static type checking] - Wrong number of parameters for method target: iterator()
       @ line 10, column 38.
             var x = Foo.<IntUnaryOperator>of((int s) -> s + 1);
                                              ^
      
      1 error
      

      Expected behavior

      Compile successfully

      Notes

      Test case adapted from the following program that uses the apache-commons-io library:

      import org.apache.commons.io.function.*;
      import java.util.function.*;
      
      class Main {
        static final void test() {
          var x = IOStream.<IntUnaryOperator>of((int s) -> s + 1);
        }
      }
      

      Attachments

        Issue Links

          Activity

            People

              emilles Eric Milles
              theosot Thodoris Sotiropoulos
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: