[
https://issues.apache.org/jira/browse/GROOVY-10254?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Eric Milles reassigned GROOVY-10254:
------------------------------------
Assignee: Eric Milles
> STC: cannot return closure from method without casting
> ------------------------------------------------------
>
> Key: GROOVY-10254
> URL: https://issues.apache.org/jira/browse/GROOVY-10254
> Project: Groovy
> Issue Type: Bug
> Components: Static compilation, Static Type Checker
> Affects Versions: 4.0.0-beta-1
> Reporter: Stefanos Chaliasos
> Assignee: Eric Milles
> Priority: Major
>
> I have the following Groovy program.
> {code:groovy}
> import java.util.function.Supplier;
> @groovy.transform.TypeChecked
> public class Main {
> public static Supplier<Integer> foo() {
> { -> 10} as Supplier<Integer> // works
> }
> public static Supplier<Integer> bar() {
> { -> 10} //fails
> }
> public static void main(String[] args) {
> Supplier<Integer> v1 = { -> 10} as Supplier<Integer> // works
> Supplier<Integer> v2 = { -> 10} // works
> Supplier<Integer> v3 = foo()
> Supplier<Integer> v4 = bar()
> }
> }
> {code}
> h2. Actual Behavior
> The program does not compile, and I get the following error.
> {code:java}
> Main.groovy: 10: [Static type checking] - Cannot return value of type
> groovy.lang.Closure<java.lang.Integer> on method returning type
> java.util.function.Supplier<java.lang.Integer>
> @ line 10, column 9.
> { -> 10} //fails
> ^
> 1 error
> {code}
> h2. Expected Behavior
> Compile successfully.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)