groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sun...@apache.org
Subject groovy git commit: Disambiguate closures from code blocks when invoking methods
Date Tue, 03 Jul 2018 23:59:48 GMT
Repository: groovy
Updated Branches:
  refs/heads/master 922223240 -> 069ffe0fe


Disambiguate closures from code blocks when invoking methods


Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/069ffe0f
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/069ffe0f
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/069ffe0f

Branch: refs/heads/master
Commit: 069ffe0fe32df82a70f085efba3e063558502c0b
Parents: 9222232
Author: sunlan <sunlan@apache.org>
Authored: Wed Jul 4 07:59:42 2018 +0800
Committer: sunlan <sunlan@apache.org>
Committed: Wed Jul 4 07:59:42 2018 +0800

----------------------------------------------------------------------
 src/antlr/GroovyParser.g4                       |  2 +-
 .../parser/antlr4/GroovyParserTest.groovy       |  4 +++
 .../test/resources/core/MethodCall_01x.groovy   | 29 ++++++++++++++++++++
 3 files changed, 34 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/069ffe0f/src/antlr/GroovyParser.g4
----------------------------------------------------------------------
diff --git a/src/antlr/GroovyParser.g4 b/src/antlr/GroovyParser.g4
index 77867da..f09e366 100644
--- a/src/antlr/GroovyParser.g4
+++ b/src/antlr/GroovyParser.g4
@@ -957,7 +957,7 @@ pathElement returns [int t]
         { $t = 2; }
 
     // Can always append a block, as foo{bar}
-    |   nls closure
+    |   closure
         { $t = 3; }
 
     // Element selection is always an option, too.

http://git-wip-us.apache.org/repos/asf/groovy/blob/069ffe0f/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/GroovyParserTest.groovy
----------------------------------------------------------------------
diff --git a/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/GroovyParserTest.groovy
b/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/GroovyParserTest.groovy
index 2384b85..2140dba 100644
--- a/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/GroovyParserTest.groovy
+++ b/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/GroovyParserTest.groovy
@@ -415,6 +415,10 @@ class GroovyParserTest extends GroovyTestCase {
         doRunAndTestAntlr4('core/NonStaticClass_01x.groovy');
     }
 
+    void "test groovy core - MethodCall"() {
+        doRunAndTestAntlr4('core/MethodCall_01x.groovy');
+    }
+
     void "test groovy core - BUG"() {
         doRunAndTestAntlr4('bugs/BUG-GROOVY-4757.groovy')
         doRunAndTestAntlr4('bugs/BUG-GROOVY-5652.groovy')

http://git-wip-us.apache.org/repos/asf/groovy/blob/069ffe0f/subprojects/parser-antlr4/src/test/resources/core/MethodCall_01x.groovy
----------------------------------------------------------------------
diff --git a/subprojects/parser-antlr4/src/test/resources/core/MethodCall_01x.groovy b/subprojects/parser-antlr4/src/test/resources/core/MethodCall_01x.groovy
new file mode 100644
index 0000000..aa66cd9
--- /dev/null
+++ b/subprojects/parser-antlr4/src/test/resources/core/MethodCall_01x.groovy
@@ -0,0 +1,29 @@
+/*
+ *  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.
+ */
+
+class MethodCall {
+    def p = 1
+}
+
+def mc = new MethodCall()
+def x = mc.p
+{ // this is a code block(not a closure)
+    mc.p = 2
+}
+assert 2 == mc.p


Mime
View raw message