Thodoris Sotiropoulos created GROOVY-10992:
----------------------------------------------

             Summary: Unexpected type mismatch when calling a parameterized 
function with a bounded type parameter
                 Key: GROOVY-10992
                 URL: https://issues.apache.org/jira/browse/GROOVY-10992
             Project: Groovy
          Issue Type: Bug
          Components: Static Type Checker
            Reporter: Thodoris Sotiropoulos


Possible regression? Groovyc 4.0.10 compiles the program

I have the following program

{code}
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);
  }
}
{code}

h3. Actual behavior

{code}
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
{code}

h3. 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)



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to