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 2022/07/02 04:08:29 UTC
[groovy] branch master updated: GROOVY-10659: Parrot Parser: named arguments does not support all key expressions
This is an automated email from the ASF dual-hosted git repository.
sunlan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git
The following commit(s) were added to refs/heads/master by this push:
new 02fbadfc80 GROOVY-10659: Parrot Parser: named arguments does not support all key expressions
02fbadfc80 is described below
commit 02fbadfc80944f7e8ac545d347f286d9498573a0
Author: Daniel Sun <su...@apache.org>
AuthorDate: Sat Jul 2 11:26:19 2022 +0800
GROOVY-10659: Parrot Parser: named arguments does not support all key expressions
---
src/antlr/GroovyParser.g4 | 2 +
src/test-resources/bugs/BUG-GROOVY-10659.groovy | 34 ++++++++++++
src/test/groovy/bugs/Groovy10659.groovy | 61 ++++++++++++++++++++++
.../groovy/parser/antlr4/GroovyParserTest.groovy | 4 ++
4 files changed, 101 insertions(+)
diff --git a/src/antlr/GroovyParser.g4 b/src/antlr/GroovyParser.g4
index 9d26199ffe..bffe4aa6d3 100644
--- a/src/antlr/GroovyParser.g4
+++ b/src/antlr/GroovyParser.g4
@@ -1053,6 +1053,8 @@ options { baseContext = primary; }
| literal #literalPrmrAlt
| gstring #gstringPrmrAlt
| parExpression #parenPrmrAlt
+ | list #listPrmrAlt
+ | map #mapPrmrAlt
;
namedArgPrimary
diff --git a/src/test-resources/bugs/BUG-GROOVY-10659.groovy b/src/test-resources/bugs/BUG-GROOVY-10659.groovy
new file mode 100644
index 0000000000..b4a89eeb18
--- /dev/null
+++ b/src/test-resources/bugs/BUG-GROOVY-10659.groovy
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+fun (
+ x: 1,
+ [a: 1]: '2'
+)
+
+fun (
+ x: 1,
+ [1, 2]: '2'
+)
+
+fun (
+ x: 1,
+ [a: 1]: '2',
+ [1, 2]: '2'
+)
diff --git a/src/test/groovy/bugs/Groovy10659.groovy b/src/test/groovy/bugs/Groovy10659.groovy
new file mode 100644
index 0000000000..e3f3c3178c
--- /dev/null
+++ b/src/test/groovy/bugs/Groovy10659.groovy
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package bugs
+
+import groovy.transform.CompileStatic
+import org.junit.Test
+
+import static groovy.test.GroovyAssert.assertScript
+
+@CompileStatic
+class Groovy10659 {
+ @Test
+ void test() {
+ assertScript '''
+ def fun = { arg ->
+ return arg
+ }
+
+ def r = fun (
+ x: 1,
+ [a: 1]: '2'
+ )
+ assert '[x:1, [a:1]:2]' == r.toString()
+
+ r = fun ([
+ x: 1,
+ [a: 1]: '2'
+ ])
+ assert '[x:1, [a:1]:2]' == r.toString()
+
+ r = fun (
+ x: 1,
+ [1, 2]: '2'
+ )
+ assert '[x:1, [1, 2]:2]' == r.toString()
+
+ r = fun (
+ x: 1,
+ [a: 1]: '2',
+ [1, 2]: '2'
+ )
+ assert '[x:1, [a:1]:2, [1, 2]:2]' == r.toString()
+ '''
+ }
+}
diff --git a/src/test/org/apache/groovy/parser/antlr4/GroovyParserTest.groovy b/src/test/org/apache/groovy/parser/antlr4/GroovyParserTest.groovy
index 0919c4fbcc..9099bac62f 100644
--- a/src/test/org/apache/groovy/parser/antlr4/GroovyParserTest.groovy
+++ b/src/test/org/apache/groovy/parser/antlr4/GroovyParserTest.groovy
@@ -529,4 +529,8 @@ final class GroovyParserTest extends GroovyTestCase {
void "test groovy core - GROOVY-10406"() {
doTest('bugs/BUG-GROOVY-10406.groovy');
}
+
+ void "test groovy core - GROOVY-10659"() {
+ doTest('bugs/BUG-GROOVY-10659.groovy');
+ }
}