Lyuben Atanasov created GROOVY-10236:
----------------------------------------

             Summary: 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


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.3.4#803005)

Reply via email to