Thodoris Sotiropoulos created GROOVY-10100:
----------------------------------------------

             Summary: groovyc infers the wrong type when using a method 
reference of a function with varargs
                 Key: GROOVY-10100
                 URL: https://issues.apache.org/jira/browse/GROOVY-10100
             Project: Groovy
          Issue Type: Bug
          Components: Static Type Checker
            Reporter: Thodoris Sotiropoulos


I have the following program

 
{code:java}
import java.util.function.Function;

class Foo<T> {
    public T method(Object... args) {
      return null;
    }
}

class Bar {
    public static <T extends Number> void test(T a) {
        Foo<T> x = new Foo<>();
        Function<String[], T> b = x::method;
        T y = b.apply(new String[] {"str"});
    }
}

public class Main {
  public static void main(String[] args) {
    Bar.test(1);
  }
}
{code}
h3. Actual Behaviour
{code:java}
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
groovy4.groovy: 14: [Static type checking] - Cannot assign value of type 
java.lang.String[] to variable of type T
 @ line 14, column 15.
           T y = b.apply(new String[] {"str"});
                 ^1 error

{code}
h3. Expected Behaviour

Compile successfully

 

Note that if I remove the `extends` from the parameterized function, the code 
compiles as expected.

 

Tested against master 
https://github.com/apache/groovy/commit/9961a67db31f7889cfb9a927ccc26c3ece0e41b9

 



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to