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 2020/12/16 00:59:01 UTC

[groovy] branch master updated: GROOVY-9859: Groovy3 doesn't parse a function property when there's a new line between return value and function name

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 4a8b01b  GROOVY-9859: Groovy3 doesn't parse a function property when there's a new line between return value and function name
4a8b01b is described below

commit 4a8b01b6f927b67e28483d5ce4f42568f08224b8
Author: Daniel Sun <su...@apache.org>
AuthorDate: Wed Dec 16 07:54:59 2020 +0800

    GROOVY-9859: Groovy3 doesn't parse a function property when there's a new line between return value and function name
---
 src/antlr/GroovyParser.g4                          |  2 +-
 src/test-resources/bugs/BUG-GROOVY-9859.groovy     | 29 ++++++++++++++++++++++
 .../groovy/parser/antlr4/GroovyParserTest.groovy   |  2 ++
 3 files changed, 32 insertions(+), 1 deletion(-)

diff --git a/src/antlr/GroovyParser.g4 b/src/antlr/GroovyParser.g4
index e6b5f7b..418778c 100644
--- a/src/antlr/GroovyParser.g4
+++ b/src/antlr/GroovyParser.g4
@@ -267,7 +267,7 @@ memberDeclaration[int t]
  *  ct  9: script, other see the comment of classDeclaration
  */
 methodDeclaration[int t, int ct]
-    :   modifiersOpt typeParameters? returnType[$ct]?
+    :   modifiersOpt typeParameters? (returnType[$ct] nls)?
         methodName formalParameters
         (
             DEFAULT nls elementValue
diff --git a/src/test-resources/bugs/BUG-GROOVY-9859.groovy b/src/test-resources/bugs/BUG-GROOVY-9859.groovy
new file mode 100644
index 0000000..18310ca
--- /dev/null
+++ b/src/test-resources/bugs/BUG-GROOVY-9859.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.
+ */
+
+public synchronized ImmutableMap<String,Pair<String,Double>>
+a(
+        List<String> params,
+        List<String> columnMapping)
+{
+    return null;
+}
+
+public class Pair<T, U> {}
+public class ImmutableMap<T, U> {}
diff --git a/src/test/org/apache/groovy/parser/antlr4/GroovyParserTest.groovy b/src/test/org/apache/groovy/parser/antlr4/GroovyParserTest.groovy
index 0ef457a..6babb90 100644
--- a/src/test/org/apache/groovy/parser/antlr4/GroovyParserTest.groovy
+++ b/src/test/org/apache/groovy/parser/antlr4/GroovyParserTest.groovy
@@ -22,6 +22,7 @@ import groovy.test.GroovyTestCase
 import org.apache.groovy.parser.antlr4.util.ASTComparatorCategory
 import org.codehaus.groovy.ast.ClassNode
 import org.codehaus.groovy.ast.FieldNode
+import org.codehaus.groovy.ast.GenericsType
 import org.codehaus.groovy.ast.MethodNode
 import org.codehaus.groovy.ast.Parameter
 import org.codehaus.groovy.ast.PropertyNode
@@ -439,6 +440,7 @@ final class GroovyParserTest extends GroovyTestCase {
         doTest('bugs/BUG-GROOVY-8913.groovy')
         doRunAndTestAntlr4('bugs/BUG-GROOVY-8991.groovy')
         doTest('bugs/BUG-GROOVY-9399.groovy')
+        doTest('bugs/BUG-GROOVY-9859.groovy', [GenericsType])
     }
 
     void "test groovy core - GROOVY-9427"() {