You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by em...@apache.org on 2021/04/20 18:36:41 UTC
[groovy] branch master updated: GROOVY-10033: check generics usage
within object initializers
This is an automated email from the ASF dual-hosted git repository.
emilles 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 011ad03 GROOVY-10033: check generics usage within object initializers
011ad03 is described below
commit 011ad03895cf9e155de3d6b204accd657a2a1f54
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Tue Apr 20 13:24:32 2021 -0500
GROOVY-10033: check generics usage within object initializers
---
.../codehaus/groovy/control/GenericsVisitor.java | 1 +
src/test/gls/generics/GenericsUsageTest.groovy | 26 ++++++++++++++++------
2 files changed, 20 insertions(+), 7 deletions(-)
diff --git a/src/main/java/org/codehaus/groovy/control/GenericsVisitor.java b/src/main/java/org/codehaus/groovy/control/GenericsVisitor.java
index 69356f2..4742b71 100644
--- a/src/main/java/org/codehaus/groovy/control/GenericsVisitor.java
+++ b/src/main/java/org/codehaus/groovy/control/GenericsVisitor.java
@@ -69,6 +69,7 @@ public class GenericsVisitor extends ClassCodeVisitorSupport {
checkGenericsUsage(face);
}
+ visitObjectInitializerStatements(node);
node.visitContents(this);
}
diff --git a/src/test/gls/generics/GenericsUsageTest.groovy b/src/test/gls/generics/GenericsUsageTest.groovy
index 5b8ec7d..a1469fe 100644
--- a/src/test/gls/generics/GenericsUsageTest.groovy
+++ b/src/test/gls/generics/GenericsUsageTest.groovy
@@ -318,27 +318,39 @@ final class GenericsUsageTest extends CompilableTestSupport {
// variable declaration
shouldFailCompilationWithMessages '''
- def method() { Map<String> map }
+ def method() { Map<String> map }
''', ['(supplied with 1 type parameter)', 'which takes 2 parameters']
shouldFailCompilationWithMessages '''
- def method() { Map<String, Map<String>> map }
+ def method() { Map<String, Map<String>> map }
''', ['(supplied with 1 type parameter)', 'which takes 2 parameters']
shouldFailCompilationWithMessages '''
- def (Map<String,String> one, Map<String> two) = [ [:], [:] ]
+ def (Map<String,String> one, Map<String> two) = [ [:], [:] ]
''', ['(supplied with 1 type parameter)', 'which takes 2 parameters']
shouldFailCompilationWithMessages '''
- Map<String>[][] array = new Map[0][0]
+ Map<String>[][] array = new Map[0][0]
''', ['(supplied with 1 type parameter)', 'which takes 2 parameters']
shouldFailCompilationWithMessages '''
- Map<String,String>[][] array = new Map<String>[0][]
+ Map<String,String>[][] array = new Map<String>[0][]
+ ''', ['(supplied with 1 type parameter)', 'which takes 2 parameters']
+ shouldFailCompilationWithMessages '''
+ class C { { Map<String> m = null } }
+ ''', ['(supplied with 1 type parameter)', 'which takes 2 parameters']
+ shouldFailCompilationWithMessages '''
+ class C { static { Map<String> m = null } }
+ ''', ['(supplied with 1 type parameter)', 'which takes 2 parameters']
+ shouldFailCompilationWithMessages '''
+ @groovy.transform.ASTTest(value={
+ Map<String> m = null
+ })
+ class C { }
''', ['(supplied with 1 type parameter)', 'which takes 2 parameters']
// casting and coercion
shouldFailCompilationWithMessages '''
- def map = (Map<String>) null
+ def map = (Map<String>) null
''', ['(supplied with 1 type parameter)', 'which takes 2 parameters']
shouldFailCompilationWithMessages '''
- def map = null as Map<String>
+ def map = null as Map<String>
''', ['(supplied with 1 type parameter)', 'which takes 2 parameters']
}