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

Cannot provide method reference to a type parameter instantiated with a SAM type

    XMLWordPrintableJSON

Details

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

    Description

      I have the following program

      import java.util.function.*;
      import java.util.stream.*;
      
      public class Test {
      
          public static void test() {
            Stream<Number> x = null;
            BiFunction<Function<String, Integer>, Number, Function<String, Integer>> y = null;
            BinaryOperator<Function<String, Integer>> z = null;
      
            x.<Function<String, Integer>>reduce(Test::m, y, z);  // fails
            x.reduce(Test::m, y, z);   // fails
            x.reduce((d) -> 1, y, z);   // works
      
          }
      
          public static Integer m(String x) { return 1; }
      }
      

      Actual behavior

      org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
      test.groovy: 12: The argument is a method reference, but the parameter type is not a functional interface
       @ line 12, column 43.
         ction<String, Integer>>reduce(Test::m, y
                                       ^
      
      test.groovy: 13: The argument is a method reference, but the parameter type is not a functional interface
       @ line 13, column 16.
               x.reduce(Test::m, y, z);   // fails
                        ^
      
      2 errors
      

      Expected behavior

      Compile successfully

      Tested against master (commit: 55c6edfd81a64ce759357a3976070c0811bff637)

      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: