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/03/28 01:01:34 UTC
[groovy] 01/01: GROOVY-9484: Closure on the next line should not be
treated as argument
This is an automated email from the ASF dual-hosted git repository.
sunlan pushed a commit to branch GROOVY-9484
in repository https://gitbox.apache.org/repos/asf/groovy.git
commit 7008524cd15677ff3a15a15214347792b2cbba8b
Author: Daniel Sun <su...@apache.org>
AuthorDate: Sat Mar 28 09:01:16 2020 +0800
GROOVY-9484: Closure on the next line should not be treated as argument
---
src/antlr/GroovyParser.g4 | 8 +--
src/spec/test/ClosuresSpecTest.groovy | 23 +++-----
src/test/groovy/CurlyBracketLayoutTest.groovy | 3 +-
.../groovy/parser/antlr4/GroovyParserTest.groovy | 4 ++
.../groovy/parser/antlr4/SyntaxErrorTest.groovy | 2 +-
.../apache/groovy/parser/antlr4/TestUtils.groovy | 7 ++-
.../src/test/resources/bugs/BUG-GROOVY-9484.groovy | 27 +--------
.../src/test/resources/core/Expression_17.groovy | 64 +++++++++++-----------
8 files changed, 57 insertions(+), 81 deletions(-)
diff --git a/src/antlr/GroovyParser.g4 b/src/antlr/GroovyParser.g4
index 2833376..9804ce5 100644
--- a/src/antlr/GroovyParser.g4
+++ b/src/antlr/GroovyParser.g4
@@ -919,12 +919,12 @@ pathElement returns [int t]
|
DOT nls NEW creator[1]
{ $t = 6; }
-
- // Can always append a block, as foo{bar}
- | closureOrLambdaExpression
- { $t = 3; }
)
+ // Can always append a block, as foo{bar}
+ | closureOrLambdaExpression
+ { $t = 3; }
+
| arguments
{ $t = 2; }
diff --git a/src/spec/test/ClosuresSpecTest.groovy b/src/spec/test/ClosuresSpecTest.groovy
index 05fc9bf..a62831b 100644
--- a/src/spec/test/ClosuresSpecTest.groovy
+++ b/src/spec/test/ClosuresSpecTest.groovy
@@ -22,39 +22,34 @@ class ClosuresSpecTest extends GroovyTestCase {
static void sink(Closure cl) {}
void testClosureSyntax() {
- sink
// tag::closure_syntax_1[]
- { item++ } // <1>
+ sink { item++ } // <1>
// end::closure_syntax_1[]
- sink
+
// tag::closure_syntax_1bis[]
- { -> item++ } // <2>
+ sink { -> item++ } // <2>
// end::closure_syntax_1bis[]
- sink
+
// tag::closure_syntax_2[]
- { println it } // <3>
+ sink { println it } // <3>
// end::closure_syntax_2[]
- sink
// tag::closure_syntax_3[]
- { it -> println it } // <4>
+ sink { it -> println it } // <4>
// end::closure_syntax_3[]
- sink
// tag::closure_syntax_4[]
- { name -> println name } // <5>
+ sink { name -> println name } // <5>
// end::closure_syntax_4[]
- sink
// tag::closure_syntax_5[]
- { String x, int y -> // <6>
+ sink { String x, int y -> // <6>
println "hey ${x} the value is ${y}"
}
// end::closure_syntax_5[]
- sink
// tag::closure_syntax_6[]
- { reader -> // <7>
+ sink { reader -> // <7>
def line = reader.readLine()
line.trim()
}
diff --git a/src/test/groovy/CurlyBracketLayoutTest.groovy b/src/test/groovy/CurlyBracketLayoutTest.groovy
index d1c0ed7..0cd3259 100644
--- a/src/test/groovy/CurlyBracketLayoutTest.groovy
+++ b/src/test/groovy/CurlyBracketLayoutTest.groovy
@@ -36,8 +36,7 @@ class CurlyBracketLayoutTest extends GroovyTestCase
}
def list = [1, 2, 3]
- list.each
- {
+ list.each {
assert it >= 1 && it <= 3
}
}
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 a32b079..8652e46 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
@@ -450,4 +450,8 @@ final class GroovyParserTest extends GroovyTestCase {
void "test groovy core - GROOVY-9449"() {
doTest('bugs/BUG-GROOVY-9449.groovy');
}
+
+ void "test groovy core - GROOVY-9484"() {
+ doTest('bugs/BUG-GROOVY-9484.groovy', [ExpressionStatement, Parameter]);
+ }
}
diff --git a/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/SyntaxErrorTest.groovy b/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/SyntaxErrorTest.groovy
index 0b789db..254caa0 100644
--- a/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/SyntaxErrorTest.groovy
+++ b/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/SyntaxErrorTest.groovy
@@ -459,7 +459,7 @@ final class SyntaxErrorTest extends GroovyTestCase {
}
}
- private static unzipScriptAndShouldFail(String entryName, List ignoreClazzList, Map<String, String> replacementsMap = [:], boolean toCheckNewParserOnly = false) {
+ private static unzipScriptAndShouldFail(String entryName, List ignoreClazzList, Map replacementsMap = [:], boolean toCheckNewParserOnly = false) {
ignoreClazzList.addAll(TestUtils.COMMON_IGNORE_CLASS_LIST)
TestUtils.unzipAndFail(SCRIPT_ZIP_PATH, entryName, TestUtils.addIgnore(ignoreClazzList, LOCATION_IGNORE_LIST), replacementsMap, toCheckNewParserOnly)
diff --git a/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/TestUtils.groovy b/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/TestUtils.groovy
index 6593fa5..0f19325 100644
--- a/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/TestUtils.groovy
+++ b/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/TestUtils.groovy
@@ -141,10 +141,11 @@ final class TestUtils {
*/
@CompileDynamic
- static unzipAndFail(String path, String entryName, conf, Map<String, String> replacementsMap = null, boolean toCheckNewParserOnly = false) {
+ static unzipAndFail(String path, String entryName, conf, Map<Object, String> replacementsMap = null, boolean toCheckNewParserOnly = false) {
String text = readZipEntry(path, entryName)
- replacementsMap?.each { k, v ->
- text = text.replace(k, v)
+
+ replacementsMap?.each {k, v ->
+ text = k instanceof String ? text.replace(k, v) : text.replaceAll(k, v);
}
def (newAST, newElapsedTime) = profile { buildAST(text, antlr4Config) }
diff --git a/src/test/groovy/CurlyBracketLayoutTest.groovy b/subprojects/parser-antlr4/src/test/resources/bugs/BUG-GROOVY-9484.groovy
similarity index 65%
copy from src/test/groovy/CurlyBracketLayoutTest.groovy
copy to subprojects/parser-antlr4/src/test/resources/bugs/BUG-GROOVY-9484.groovy
index d1c0ed7..3009746 100644
--- a/src/test/groovy/CurlyBracketLayoutTest.groovy
+++ b/subprojects/parser-antlr4/src/test/resources/bugs/BUG-GROOVY-9484.groovy
@@ -16,29 +16,6 @@
* specific language governing permissions and limitations
* under the License.
*/
-package groovy
-import groovy.test.GroovyTestCase
-
-class CurlyBracketLayoutTest extends GroovyTestCase
-{
- void testBracketPlacement()
- {
- def foo = "abc"
-
- if (foo.contains("b"))
- {
- // expected
- }
- else
- {
- fail("Should have found 'b' inside $foo")
- }
-
- def list = [1, 2, 3]
- list.each
- {
- assert it >= 1 && it <= 3
- }
- }
-}
\ No newline at end of file
+modification | expected
+{ Instant i, ZoneId z -> i.plusSeconds(1) } | defaultInstant.plusSeconds(1)
diff --git a/subprojects/parser-antlr4/src/test/resources/core/Expression_17.groovy b/subprojects/parser-antlr4/src/test/resources/core/Expression_17.groovy
index 89309fb..0eecc1c 100644
--- a/subprojects/parser-antlr4/src/test/resources/core/Expression_17.groovy
+++ b/subprojects/parser-antlr4/src/test/resources/core/Expression_17.groovy
@@ -27,15 +27,15 @@ a.m(x: 1, y: 2, z: 3) {
}
-a.m(x: 1, y: 2, z: 3)
-
-{
- println('named arguments');
-}
-
-{
- println('named arguments');
-}
+//a.m(x: 1, y: 2, z: 3)
+//
+//{
+// println('named arguments');
+//}
+//
+//{
+// println('named arguments');
+//}
@@ -49,16 +49,16 @@ a.m(1, 2, 3) {
println('normal arguments');
}
-a.m(1, 2, 3)
-
-{
- println('normal arguments');
-}
-
-
-{
- println('normal arguments');
-}
+//a.m(1, 2, 3)
+//
+//{
+// println('normal arguments');
+//}
+//
+//
+//{
+// println('normal arguments');
+//}
@@ -82,19 +82,19 @@ m {
}
-m
-
-{
- println('closure arguments');
-}
-
-{
- println('closure arguments');
-}
-
-{
- println('closure arguments');
-}
+//m
+//
+//{
+// println('closure arguments');
+//}
+//
+//{
+// println('closure arguments');
+//}
+//
+//{
+// println('closure arguments');
+//}
'm' {
println('closure arguments');