You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Stefanos Chaliasos (Jira)" <ji...@apache.org> on 2021/06/08 10:35:00 UTC
[jira] [Created] (GROOVY-10128) Cannot assign closure with long as
return type to java.util.function.Function
Stefanos Chaliasos created GROOVY-10128:
-------------------------------------------
Summary: Cannot assign closure with long as return type to java.util.function.Function<X, Number>
Key: GROOVY-10128
URL: https://issues.apache.org/jira/browse/GROOVY-10128
Project: Groovy
Issue Type: Bug
Components: Static compilation, Static Type Checker
Affects Versions: 4.0.0-alpha-3, 3.0.8
Reporter: Stefanos Chaliasos
I have the following Groovy program.
{code:groovy}
import java.util.function.Function;
@groovy.transform.TypeChecked
class Main {
public static void main(String[] args) {
Function<String, Number> x = { y ->
final long d = 1;
return d;
};
}
}
{code}
h2. Actual Behavior
The program does not compile, and I get the following error.
{code:java}
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Main.groovy: 6: [Static type checking] - Incompatible generic argument types. Cannot assign java.util.function.Function <java.lang.String, java.lang.Long> to: java.util.function.Function <String, Number>
@ line 6, column 36.
Function<String, Number> x = { y ->
^
1 error
{code}
h2. Expected Behavior
Compile successfully.
h2. Comment
Note that javac accepts this program.
h2. Affected Version
This programs have been tested with the compiler from the master (commit: 05a39632565bee88949c8db9d56b9f9598321fc2), 4.0.0-alpha-3, and 3.0.8.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)