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

Unexpected type mismatch when calling a parameterized function with a bounded type parameter

    XMLWordPrintableJSON

Details

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

    Description

      Possible regression? Groovyc 4.0.10 compiles the program

      I have the following program

      import java.util.function.Supplier;
      import java.util.function.BinaryOperator;
      import java.util.stream.Stream;
      
      class Main {
        static final <X extends Number> void test() {
          Supplier<Stream<X>> x = null;
          X y = null;
          BinaryOperator<X> z = null;
      
          X result = x.get().reduce(y, z);
        }
      }
      

      Actual behavior

      org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
      test.groovy: 11: [Static type checking] - Cannot call java.util.stream.Stream#reduce(X, java.util.function.BinaryOperator<X extends java.lang.Number>) with arguments [X, java.util.function.BinaryOperator<X>]
       @ line 11, column 16.
             X result = x.get().reduce(y, z);
                        ^
      
      1 error
      

      Expected behavior

      Compile successfully

      Notes: The type parameter X should have an upper bound in order to trigger the error.

      Tested against master (commit: a29ce1ce64d565526b70e145ace665dd0617ec9b)

      Attachments

        Activity

          People

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

            Dates

              Created:
              Updated: