You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Paul King (Jira)" <ji...@apache.org> on 2023/02/10 21:40:00 UTC
[jira] [Closed] (GROOVY-10699) Unable to infer type argument from the parameter type of a lambda
[ https://issues.apache.org/jira/browse/GROOVY-10699?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Paul King closed GROOVY-10699.
------------------------------
> Unable to infer type argument from the parameter type of a lambda
> -----------------------------------------------------------------
>
> Key: GROOVY-10699
> URL: https://issues.apache.org/jira/browse/GROOVY-10699
> Project: Groovy
> Issue Type: Bug
> Components: Static Type Checker
> Reporter: Thodoris Sotiropoulos
> Assignee: Eric Milles
> Priority: Major
> Fix For: 4.0.5
>
>
> I have the following program:
> {code}
> 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
> }
> }
> {code}
> h3. Actual behavior
> {code}
> 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
> {code}
> h3. 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).
--
This message was sent by Atlassian Jira
(v8.20.10#820010)