Repository: groovy
Updated Branches:
  refs/heads/GROOVY_2_5_X f81747ca0 -> a37b136c8


GROOVY-8211: part two - check declaration expressions


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

Branch: refs/heads/GROOVY_2_5_X
Commit: a37b136c832ff38fdd3e2f4a4677a1f283af0fbe
Parents: f81747c
Author: Paul King <pa...@asert.com.au>
Authored: Thu Apr 12 23:38:37 2018 +1000
Committer: Paul King <pa...@asert.com.au>
Committed: Thu Apr 12 23:38:37 2018 +1000

----------------------------------------------------------------------
 .../codehaus/groovy/control/GenericsVisitor.java  | 18 ++++++++++++++++++
 src/test/gls/generics/GenericsTest.groovy         |  6 ++++++
 src/test/groovy/bugs/Groovy4190Bug.groovy         |  4 ++--
 .../org/codehaus/groovy/ast/LineColumnCheck.txt   |  6 +++---
 4 files changed, 29 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/a37b136c/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 b4f3854..e623b18 100644
--- a/src/main/java/org/codehaus/groovy/control/GenericsVisitor.java
+++ b/src/main/java/org/codehaus/groovy/control/GenericsVisitor.java
@@ -26,6 +26,9 @@ import org.codehaus.groovy.ast.InnerClassNode;
 import org.codehaus.groovy.ast.MethodNode;
 import org.codehaus.groovy.ast.Parameter;
 import org.codehaus.groovy.ast.expr.ConstructorCallExpression;
+import org.codehaus.groovy.ast.expr.DeclarationExpression;
+import org.codehaus.groovy.ast.expr.Expression;
+import org.codehaus.groovy.ast.expr.TupleExpression;
 
 /**
  * Verify correct usage of generics.
@@ -86,6 +89,21 @@ public class GenericsVisitor extends ClassCodeVisitorSupport 
{
         super.visitMethod(node);
     }
 
+    @Override
+    public void visitDeclarationExpression(DeclarationExpression expression) {
+        if (expression.isMultipleAssignmentDeclaration()) {
+            TupleExpression tExpr = expression.getTupleExpression();
+            for (Expression nextExpr : tExpr.getExpressions()) {
+                ClassNode declType = nextExpr.getType();
+                checkGenericsUsage(declType, declType.redirect());
+            }
+        } else {
+            ClassNode declType = expression.getVariableExpression().getType();
+            checkGenericsUsage(declType, declType.redirect());
+        }
+        super.visitDeclarationExpression(expression);
+    }
+
     private boolean checkWildcard(ClassNode cn) {
         ClassNode sn = cn.getUnresolvedSuperClass(false);
         if (sn == null) return false;

http://git-wip-us.apache.org/repos/asf/groovy/blob/a37b136c/src/test/gls/generics/GenericsTest.groovy
----------------------------------------------------------------------
diff --git a/src/test/gls/generics/GenericsTest.groovy 
b/src/test/gls/generics/GenericsTest.groovy
index 6d61ebf..b547ed9 100644
--- a/src/test/gls/generics/GenericsTest.groovy
+++ b/src/test/gls/generics/GenericsTest.groovy
@@ -500,6 +500,12 @@ import java.util.concurrent.atomic.AtomicInteger
         shouldFailCompilationWithMessages '''
             class MyClass { Map<String, Map<String>> map }
         ''', ['(supplied with 1 type parameter)', 'which takes 2 parameters']
+        shouldFailCompilationWithMessages '''
+             def method() { Map<String> map }
+        ''', ['(supplied with 1 type parameter)', 'which takes 2 parameters']
+        shouldFailCompilationWithMessages '''
+             def method() { Map<String, Map<String>> map }
+        ''', ['(supplied with 1 type parameter)', 'which takes 2 parameters']
         assertScript '''
             List<String> ss = new LinkedList<>()
         '''

http://git-wip-us.apache.org/repos/asf/groovy/blob/a37b136c/src/test/groovy/bugs/Groovy4190Bug.groovy
----------------------------------------------------------------------
diff --git a/src/test/groovy/bugs/Groovy4190Bug.groovy 
b/src/test/groovy/bugs/Groovy4190Bug.groovy
index 1250a69..8e06158 100644
--- a/src/test/groovy/bugs/Groovy4190Bug.groovy
+++ b/src/test/groovy/bugs/Groovy4190Bug.groovy
@@ -41,11 +41,11 @@ class Groovy4190Bug extends CompilableTestSupport {
     
     void testGenericsUsageInMethodCall2() {
         shouldCompile """
-            class Test4190V2<E> {
+            class Test4190V2<K,V> {
                 public static void main(String[] args) {
                     Test4190V2<Integer, String> t = Test4190V2.<Integer, 
String>create();
                 }
             }
         """
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/groovy/blob/a37b136c/src/test/org/codehaus/groovy/ast/LineColumnCheck.txt
----------------------------------------------------------------------
diff --git a/src/test/org/codehaus/groovy/ast/LineColumnCheck.txt 
b/src/test/org/codehaus/groovy/ast/LineColumnCheck.txt
index 635506f..067f0b0 100644
--- a/src/test/org/codehaus/groovy/ast/LineColumnCheck.txt
+++ b/src/test/org/codehaus/groovy/ast/LineColumnCheck.txt
@@ -384,9 +384,9 @@ Collection<? super File> c
 [ClassNode,(1:20),(1:24)]
 
 ###typeArgumentsLowerAndUpperBound:::
-Collection<? extends String,? super File> c
-:::[ClassNode,(1:1),(1:11)][GenericsType,(1:12),(1:28)][ClassNode,(-1:-1),(-1:-1)][ClassNode,(1:22),(1:28)];
-[GenericsType,(1:29),(1:41)][ClassNode,(-1:-1),(-1:-1)][ClassNode,(1:37),(1:41)]
+Map<? extends String,? super File> m
+:::[ClassNode,(1:1),(1:4)][GenericsType,(1:5),(1:21)][ClassNode,(-1:-1),(-1:-1)][ClassNode,(1:15),(1:21)];
+[GenericsType,(1:22),(1:34)][ClassNode,(-1:-1),(-1:-1)][ClassNode,(1:30),(1:34)]
 
 ###typeArgumentNested:::
 class C<Y,T extends Map<String,Map<Y,Integer>>> {}

Reply via email to