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/8ee3bd96
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/8ee3bd96
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/8ee3bd96

Branch: refs/heads/GROOVY_2_6_X
Commit: 8ee3bd96155663e93f8220c8a271de5a008d57ef
Parents: 2c9197f
Author: Paul King <pa...@asert.com.au>
Authored: Thu Apr 12 20:06:22 2018 +1000
Committer: Paul King <pa...@asert.com.au>
Committed: Thu Apr 12 23:42:02 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/8ee3bd96/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/8ee3bd96/src/test/gls/generics/GenericsTest.groovy
----------------------------------------------------------------------
diff --git a/src/test/gls/generics/GenericsTest.groovy 
b/src/test/gls/generics/GenericsTest.groovy
index a7865cd..5512738 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