[
https://issues.apache.org/jira/browse/GROOVY-8778?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16607856#comment-16607856
]
ASF GitHub Bot commented on GROOVY-8778:
----------------------------------------
Github user danielsun1106 commented on a diff in the pull request:
https://github.com/apache/groovy/pull/792#discussion_r216116090
--- Diff:
subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java
---
@@ -2337,14 +2337,11 @@ public Expression
visitPathElement(PathElementContext ctx) {
this.visitNamedPropertyArgs(ctx.namedPropertyArgs());
Expression right;
- if (mapEntryExpressionList.size() == 1) {
- MapEntryExpression mapEntryExpression =
mapEntryExpressionList.get(0);
-
- if (mapEntryExpression.getKeyExpression() instanceof
SpreadMapExpression) {
- right = mapEntryExpression.getKeyExpression();
- } else {
- right = mapEntryExpression;
- }
+ if (mapEntryExpressionList.size() == 0) {
+ // expecting list of MapEntryExpressions later so use
SpreadMap to smuggle empty MapExpression to later stages
+ right = new SpreadMapExpression(configureAST(new
MapExpression(), ctx.namedPropertyArgs()));
--- End diff --
The implementation of parser should not decouple with back end(i.e. not
rely on the implementation of back end).
If the implementation of resolve visitor changes in the future, the
expression is not thrown away, the node position is missing.
> Cast short-hand breaks for empty map
> ------------------------------------
>
> Key: GROOVY-8778
> URL: https://issues.apache.org/jira/browse/GROOVY-8778
> Project: Groovy
> Issue Type: Bug
> Affects Versions: 3.0.0-alpha-3
> Reporter: Paul King
> Assignee: Paul King
> Priority: Major
> Labels: breaking
>
> We support:
> {code}
> println Date[time:0]
> def map = [time:0]
> println Date[*:map]
> map = [:]
> println Date[*:map]
> {code}
> but not:
> {code}
> println Date[:]
> {code}
> This is a breaking change since we currently support printing an empty map
> without brackets but would require them after this change:
> {code}
> println [:]
> {code}
> would need to be:
> {code}
> println([:])
> {code}
> But we require the brackets for lists (empty and non-empty) and non-empty
> maps already.
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)