Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
None
-
None
Description
I have the following program:
import java.util.function.Function; import java.util.function.Consumer; import java.util.function.Supplier; class A<T> { A(C<T> x) {} } class C<T> { C(T x ) {} } class B<X> { B(Consumer<X> x) {} } class D<X> { D(Supplier<X> x) {} } class Test { void test() { A<String> x = new A<>(new C<>("str")); // type inference works (type inferred based on the constant "str") D<String> z = new D<>(() -> "fda"); // type inference works (type inferred based on the return type of the lambda) B<String> y = new B<>((String e) -> {return;} ); // type inference doesn't work } }
Actual behavior
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: test.groovy: 27: [Static type checking] - Expected type java.lang.Object for lambda parameter: e @ line 27, column 28. B<String> y = new B<>((String e) -> {return;} ); // type inference doesn't work ^ 1 error
Expected behavior
Compile successfully
Tested against master (commit: 63bcab1bf13fb3811626fb1727c22e86528feb7f)
*Notes*: As indicated in the accompanying test case, the compiler is unable to infer the type argument of a parameterized constructor call from the parameter of a lambda, although it works for any other case (including the return type of a lambda).