You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by su...@apache.org on 2017/04/22 01:19:17 UTC
[10/40] groovy git commit: GROOVY-8150: Inconsistency in multiple
assignment with single variable
GROOVY-8150: Inconsistency in multiple assignment with single variable
Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/23c6cdc6
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/23c6cdc6
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/23c6cdc6
Branch: refs/heads/parrot
Commit: 23c6cdc6902df8ff58a85e28651ffff7b58473d0
Parents: ca83d50
Author: sunlan <su...@apache.org>
Authored: Tue Apr 18 00:32:26 2017 +0800
Committer: sunlan <su...@apache.org>
Committed: Tue Apr 18 00:38:41 2017 +0800
----------------------------------------------------------------------
.../org/apache/groovy/parser/antlr4/AstBuilder.java | 14 ++++++++++++++
.../groovy/parser/antlr4/SyntaxErrorTest.groovy | 1 +
.../src/test/resources/bugs/BUG-GROOVY-8150.groovy | 3 +++
3 files changed, 18 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/groovy/blob/23c6cdc6/subprojects/groovy-parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java
----------------------------------------------------------------------
diff --git a/subprojects/groovy-parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java b/subprojects/groovy-parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java
index 9f4eca3..a02286f 100644
--- a/subprojects/groovy-parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java
+++ b/subprojects/groovy-parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java
@@ -1770,6 +1770,14 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object> implements Groov
expression.putNodeMetaData(IS_INSIDE_PARENTHESES, true);
+ Integer insideParenLevel = expression.getNodeMetaData(INSIDE_PARENTHESES_LEVEL);
+ if (asBoolean((Object) insideParenLevel)) {
+ insideParenLevel++;
+ } else {
+ insideParenLevel = 1;
+ }
+ expression.putNodeMetaData(INSIDE_PARENTHESES_LEVEL, insideParenLevel);
+
return this.configureAST(expression, ctx);
}
@@ -2520,6 +2528,10 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object> implements Groov
if (leftExpr instanceof VariableExpression
&& isTrue(leftExpr, IS_INSIDE_PARENTHESES)) { // it is a special multiple assignment whose variable count is only one, e.g. (a) = [1]
+ if ((Integer) leftExpr.getNodeMetaData(INSIDE_PARENTHESES_LEVEL) > 1) {
+ throw createParsingFailedException("Nested parenthesis is not allowed in multiple assignment, e.g. ((a)) = b", ctx);
+ }
+
return this.configureAST(
new BinaryExpression(
this.configureAST(new TupleExpression(leftExpr), ctx.left),
@@ -4474,6 +4486,8 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object> implements Groov
private static final Logger LOGGER = Logger.getLogger(AstBuilder.class.getName());
private static final String IS_INSIDE_PARENTHESES = "_IS_INSIDE_PARENTHESES";
+ private static final String INSIDE_PARENTHESES_LEVEL = "_INSIDE_PARENTHESES_LEVEL";
+
private static final String IS_INSIDE_INSTANCEOF_EXPR = "_IS_INSIDE_INSTANCEOF_EXPR";
private static final String IS_SWITCH_DEFAULT = "_IS_SWITCH_DEFAULT";
private static final String IS_NUMERIC = "_IS_NUMERIC";
http://git-wip-us.apache.org/repos/asf/groovy/blob/23c6cdc6/subprojects/groovy-parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/SyntaxErrorTest.groovy
----------------------------------------------------------------------
diff --git a/subprojects/groovy-parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/SyntaxErrorTest.groovy b/subprojects/groovy-parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/SyntaxErrorTest.groovy
index 5b7fec5..79011b7 100644
--- a/subprojects/groovy-parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/SyntaxErrorTest.groovy
+++ b/subprojects/groovy-parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/SyntaxErrorTest.groovy
@@ -123,6 +123,7 @@ class SyntaxErrorTest extends GroovyTestCase {
void "test groovy core - BUGs"() {
TestUtils.doRunAndShouldFail('bugs/BUG-GROOVY-5318.groovy');
+ TestUtils.doRunAndShouldFail('bugs/BUG-GROOVY-8150.groovy');
}
void "test groovy core - DoWhile"() {
http://git-wip-us.apache.org/repos/asf/groovy/blob/23c6cdc6/subprojects/groovy-parser-antlr4/src/test/resources/bugs/BUG-GROOVY-8150.groovy
----------------------------------------------------------------------
diff --git a/subprojects/groovy-parser-antlr4/src/test/resources/bugs/BUG-GROOVY-8150.groovy b/subprojects/groovy-parser-antlr4/src/test/resources/bugs/BUG-GROOVY-8150.groovy
new file mode 100644
index 0000000..0c8b676
--- /dev/null
+++ b/subprojects/groovy-parser-antlr4/src/test/resources/bugs/BUG-GROOVY-8150.groovy
@@ -0,0 +1,3 @@
+def a
+def b = [1]
+((a)) = b
\ No newline at end of file