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 03:26:48 UTC

[groovy] 01/01: 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 GROOVY-10659
in repository https://gitbox.apache.org/repos/asf/groovy.git

commit 3146d0596d21ec69d223a9aa95f55de7bf7192c0
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                          |  1 +
 src/test-resources/bugs/BUG-GROOVY-10659.groovy    | 23 ++++++++++
 src/test/groovy/bugs/Groovy10659.groovy            | 50 ++++++++++++++++++++++
 .../groovy/parser/antlr4/GroovyParserTest.groovy   |  4 ++
 4 files changed, 78 insertions(+)

diff --git a/src/antlr/GroovyParser.g4 b/src/antlr/GroovyParser.g4
index 9d26199ffe..c2edbfdebd 100644
--- a/src/antlr/GroovyParser.g4
+++ b/src/antlr/GroovyParser.g4
@@ -1053,6 +1053,7 @@ options { baseContext = primary; }
     |   literal                                                                             #literalPrmrAlt
     |   gstring                                                                             #gstringPrmrAlt
     |   parExpression                                                                       #parenPrmrAlt
+    |   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..0de5d6e60d
--- /dev/null
+++ b/src/test-resources/bugs/BUG-GROOVY-10659.groovy
@@ -0,0 +1,23 @@
+/*
+ *  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'
+)
diff --git a/src/test/groovy/bugs/Groovy10659.groovy b/src/test/groovy/bugs/Groovy10659.groovy
new file mode 100644
index 0000000000..96acc28269
--- /dev/null
+++ b/src/test/groovy/bugs/Groovy10659.groovy
@@ -0,0 +1,50 @@
+/*
+ *  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
+            }
+            
+            final expected = '[x:1, [a:1]:2]'
+            
+            def r = fun (
+                x: 1,
+                [a: 1]: '2'
+            )
+            assert expected == r.toString()
+            
+            r = fun ([
+                x: 1,
+                [a: 1]: '2'
+            ]) 
+            assert expected == 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');
+    }
 }