Skip to content

Commit d498406

Browse files
committed
GROOVY-10236
1 parent 4665fa1 commit d498406

File tree

5 files changed

+8
-13
lines changed

5 files changed

+8
-13
lines changed

base-test/org.eclipse.jdt.groovy.core.tests.compiler/src/org/eclipse/jdt/groovy/core/tests/basic/GroovySimpleTests.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ public void testLambdaBasic() {
525525
"Supplier<String> s = () -> 'hello'\n" +
526526
"print s.get()\n" +
527527
"\n" +
528-
"Consumer<String> c = x -> print(x)\n" +
528+
"Consumer<String> c = (x -> print x)\n" + // GROOVY-10236
529529
"c.accept(' ')\n" +
530530
"\n" +
531531
"Function<Integer, String> f = (Integer i) -> { 'world' }\n" +

base/org.codehaus.groovy40/src/GroovyParser.g4

+1-1
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ standardLambdaParameters
486486

487487
lambdaBody
488488
: block
489-
| expression
489+
| statementExpression
490490
;
491491

492492
// CLOSURE

base/org.codehaus.groovy40/src/org/apache/groovy/parser/antlr4/AstBuilder.java

+1-6
Original file line numberDiff line numberDiff line change
@@ -4274,15 +4274,10 @@ public Parameter[] visitStandardLambdaParameters(final StandardLambdaParametersC
42744274

42754275
@Override
42764276
public Statement visitLambdaBody(final LambdaBodyContext ctx) {
4277-
if (asBoolean(ctx.expression())) {
4278-
return configureAST(new ExpressionStatement((Expression) this.visit(ctx.expression())), ctx);
4279-
}
4280-
42814277
if (asBoolean(ctx.block())) {
42824278
return configureAST(this.visitBlock(ctx.block()), ctx);
42834279
}
4284-
4285-
throw createParsingFailedException("Unsupported lambda body: " + ctx.getText(), ctx);
4280+
return configureAST((Statement) this.visit(ctx.statementExpression()), ctx);
42864281
}
42874282

42884283
@Override

base/org.codehaus.groovy40/src/org/apache/groovy/parser/antlr4/GroovyParser.interp

+1-1
Large diffs are not rendered by default.

base/org.codehaus.groovy40/src/org/apache/groovy/parser/antlr4/GroovyParser.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -4622,8 +4622,8 @@ public static class LambdaBodyContext extends GroovyParserRuleContext {
46224622
public BlockContext block() {
46234623
return getRuleContext(BlockContext.class,0);
46244624
}
4625-
public ExpressionContext expression() {
4626-
return getRuleContext(ExpressionContext.class,0);
4625+
public StatementExpressionContext statementExpression() {
4626+
return getRuleContext(StatementExpressionContext.class,0);
46274627
}
46284628
public LambdaBodyContext(ParserRuleContext parent, int invokingState) {
46294629
super(parent, invokingState);
@@ -4656,7 +4656,7 @@ public final LambdaBodyContext lambdaBody() throws RecognitionException {
46564656
enterOuterAlt(_localctx, 2);
46574657
{
46584658
setState(869);
4659-
expression(0);
4659+
statementExpression();
46604660
}
46614661
break;
46624662
}
@@ -13420,7 +13420,7 @@ private boolean pathExpression_sempred(PathExpressionContext _localctx, int pred
1342013420
"\5\u0146\u00a4\2\u035e\u035f\5\u0082B\2\u035f}\3\2\2\2\u0360\u0361\5^"+
1342113421
"\60\2\u0361\177\3\2\2\2\u0362\u0365\5^\60\2\u0363\u0365\5@!\2\u0364\u0362"+
1342213422
"\3\2\2\2\u0364\u0363\3\2\2\2\u0365\u0081\3\2\2\2\u0366\u0369\5\u009eP"+
13423-
"\2\u0367\u0369\5\u00f0y\2\u0368\u0366\3\2\2\2\u0368\u0367\3\2\2\2\u0369"+
13423+
"\2\u0367\u0369\5\u00e6t\2\u0368\u0366\3\2\2\2\u0368\u0367\3\2\2\2\u0369"+
1342413424
"\u0083\3\2\2\2\u036a\u0373\7Y\2\2\u036b\u036f\5\u0146\u00a4\2\u036c\u036d"+
1342513425
"\5`\61\2\u036d\u036e\5\u0146\u00a4\2\u036e\u0370\3\2\2\2\u036f\u036c\3"+
1342613426
"\2\2\2\u036f\u0370\3\2\2\2\u0370\u0371\3\2\2\2\u0371\u0372\7T\2\2\u0372"+

0 commit comments

Comments
 (0)