GROOVY-8211: part one - also show nested type parameter arity mismatches

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

Branch: refs/heads/master
Commit: a012487b53fccab125b3d9ca8d31eb979570a401
Parents: cb7db51
Author: Paul King <pa...@asert.com.au>
Authored: Thu Apr 12 20:06:22 2018 +1000
Committer: Paul King <pa...@asert.com.au>
Committed: Fri Apr 13 03:25:32 2018 +1000

----------------------------------------------------------------------
 .../org/codehaus/groovy/control/GenericsVisitor.java   | 13 ++++++++++---
 src/test/gls/generics/GenericsTest.groovy              | 12 ++++++++++++
 2 files changed, 22 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/a012487b/src/main/java/org/codehaus/groovy/control/GenericsVisitor.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/control/GenericsVisitor.java 
b/src/main/java/org/codehaus/groovy/control/GenericsVisitor.java
index 53885cf..b4f3854 100644
--- a/src/main/java/org/codehaus/groovy/control/GenericsVisitor.java
+++ b/src/main/java/org/codehaus/groovy/control/GenericsVisitor.java
@@ -28,8 +28,13 @@ import org.codehaus.groovy.ast.Parameter;
 import org.codehaus.groovy.ast.expr.ConstructorCallExpression;
 
 /**
- * class used to verify correct usage of generics in
- * class header (class and superclass declaration)
+ * Verify correct usage of generics.
+ * This includes:
+ * <ul>
+ * <li>class header (class and superclass declaration)</li>
+ * <li>arity of type parameters for fields, parameters, local variables</li>
+ * <li>invalid diamond &;t;&gt; usage</li>
+ * </ul>
  */
 public class GenericsVisitor extends ClassCodeVisitorSupport {
     private final SourceUnit source;
@@ -135,10 +140,12 @@ public class GenericsVisitor extends 
ClassCodeVisitorSupport {
             addError(message, n);
             return;
         }
-        // check bounds
         for (int i = 0; i < nTypes.length; i++) {
             ClassNode nType = nTypes[i].getType();
             ClassNode cnType = cnTypes[i].getType();
+            // check nested type parameters
+            checkGenericsUsage(nType, nType.redirect());
+            // check bounds
             if (!nType.isDerivedFrom(cnType)) {
                 if (cnType.isInterface() && nType.implementsInterface(cnType)) 
continue;
                 addError("The type " + nTypes[i].getName() +

http://git-wip-us.apache.org/repos/asf/groovy/blob/a012487b/src/test/gls/generics/GenericsTest.groovy
----------------------------------------------------------------------
diff --git a/src/test/gls/generics/GenericsTest.groovy 
b/src/test/gls/generics/GenericsTest.groovy
index 59fea06..0f9e0ed 100644
--- a/src/test/gls/generics/GenericsTest.groovy
+++ b/src/test/gls/generics/GenericsTest.groovy
@@ -564,6 +564,18 @@ import java.util.concurrent.atomic.AtomicInteger
         shouldFailCompilationWithMessages '''
             def now = new Date<Calendar>()
         ''', ['supplied with 1 type parameter', 'which takes no parameters']
+        shouldFailCompilationWithMessages '''
+            def method(Map<String> map) { map.toString() }
+        ''', ['(supplied with 1 type parameter)', 'which takes 2 parameters']
+        shouldFailCompilationWithMessages '''
+            def method(Map<String, Map<String>> map) { map.toString() }
+        ''', ['(supplied with 1 type parameter)', 'which takes 2 parameters']
+        shouldFailCompilationWithMessages '''
+            class MyClass { Map<String> map }
+        ''', ['(supplied with 1 type parameter)', 'which takes 2 parameters']
+        shouldFailCompilationWithMessages '''
+            class MyClass { Map<String, Map<String>> map }
+        ''', ['(supplied with 1 type parameter)', 'which takes 2 parameters']
         assertScript '''
             List<String> ss = new LinkedList<>()
         '''

Reply via email to