[ 
https://issues.apache.org/jira/browse/GROOVY-11244?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17798221#comment-17798221
 ] 

Daniel Sun commented on GROOVY-11244:
-------------------------------------

It is an ambiguous code for parser. Adding a parentheses to the expression at 
the right hand should work too.

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

class Test {
  void test() {
    Closure<String> clo = {
      Function<Integer, Integer> x = ((z) -> 1 + z);
      return "f";
    }
  }
}
{code}


> Cannot define Java-like lambda inside closure
> ---------------------------------------------
>
>                 Key: GROOVY-11244
>                 URL: https://issues.apache.org/jira/browse/GROOVY-11244
>             Project: Groovy
>          Issue Type: Bug
>          Components: parser-antlr4
>            Reporter: Thodoris Sotiropoulos
>            Priority: Minor
>
> I have the following program
> {code}
> import java.util.function.Function;
> class Test {
>   void test() {
>     Closure<String> clo = {
>       Function<Integer, Integer> x = (z) -> 1 + z;
>       return "f";
>     }
>   }
> }
> {code}
> h3. Actual behavior
> {code}
> org.codehaus.groovy.control.MultipleCompilationErrorsException: startup 
> failed:
> test.groovy: 6: [Static type checking] - The variable [z] is undeclared.
>  @ line 6, column 49.
>    eger, Integer> x = (z) -> 1 + z;
>                                  ^
> test.groovy: 6: [Static type checking] - Cannot find matching method 
> int#plus(java.lang.Object). Please check if the declared type is correct and 
> if the method exists.
>  @ line 6, column 45.
>    <Integer, Integer> x = (z) -> 1 + z;
>                                  ^
> test.groovy: 6: [Static type checking] - The variable [z] is undeclared.
>  @ line 6, column 38.
>          Function<Integer, Integer> x = (z) -> 1 + z;
>                                         ^
> 3 errors
> {code}
> h3. Expected behavior
> Compile successfully



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to