Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GROOVY-11601: remove support for expression list in for-each statement #2174

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/antlr/GroovyParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,6 @@ originalForControl

forInit
: localVariableDeclaration
| expressionList[false]
;

forUpdate
Expand Down
13 changes: 2 additions & 11 deletions src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -545,10 +545,6 @@ public Expression visitForInit(final ForInitContext ctx) {
}
}

if (asBoolean(ctx.expressionList())) {
return this.translateExpressionList(ctx.expressionList());
}

throw createParsingFailedException("Unsupported for init: " + ctx.getText(), ctx);
}

Expand All @@ -558,14 +554,9 @@ public Expression visitForUpdate(final ForUpdateContext ctx) {
return EmptyExpression.INSTANCE;
}

return this.translateExpressionList(ctx.expressionList());
}

private Expression translateExpressionList(final ExpressionListContext ctx) {
List<Expression> expressionList = this.visitExpressionList(ctx);

var expressionList = this.visitExpressionList(ctx.expressionList());
if (expressionList.size() == 1) {
return configureAST(expressionList.get(0), ctx);
return configureAST(expressionList.get(0), ctx); // one Expression
} else {
return configureAST(new ClosureListExpression(expressionList), ctx);
}
Expand Down