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 2022/02/03 22:33:00 UTC
[jira] [Closed] (GROOVY-10236) Parser fails to parse a single-statement lambda when omitting parentheses for method call
[ https://issues.apache.org/jira/browse/GROOVY-10236?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Paul King closed GROOVY-10236.
------------------------------
> Parser fails to parse a single-statement lambda when omitting parentheses for method call
> ------------------------------------------------------------------------------------------
>
> Key: GROOVY-10236
> URL: https://issues.apache.org/jira/browse/GROOVY-10236
> Project: Groovy
> Issue Type: Bug
> Components: parser, parser-antlr4
> Affects Versions: 4.0.0-beta-1
> Reporter: Lyuben Atanasov
> Assignee: Daniel Sun
> Priority: Major
> Fix For: 4.0.0-beta-2
>
>
> The parser fails to parse the following code:
> {code}
> class Test {
> public void test() {
> [1, 2, 3, 4, 5].stream().forEach(num -> println "$num");
> }
> }
> {code}
> The produced error is:
> {noformat}
> Exception in thread "main" org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
> Script_30c2a85fbeaac50f95df1e8ce776b5dd.groovy: 4: Unexpected input: '(' @ line 4, column 41.
> , 2, 3, 4, 5].stream().forEach(num -> pr
> ^
> {noformat}
> This problem appears only after 4.0.0-beta-1.
> The following expressions are parsed successfully:
> {code}
> [1, 2, 3, 4, 5].stream().forEach(num -> { println "$num" });
> [1, 2, 3, 4, 5].stream().forEach(num -> println("$num"));
> {code}
> There is also something curious: if I modify the original code and wrap the parameter {{num}} in parentheses ({{.forEach((num) -> println "$num")}}), the parser does not complain, but {{println}} is recognized as a variable rather than a method.
--
This message was sent by Atlassian Jira
(v8.20.1#820001)