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

Branch: refs/heads/master
Commit: 12d0f4431dcbe419e86cdd23ca7f71670fea4e6e
Parents: a012487
Author: Paul King <pa...@asert.com.au>
Authored: Thu Apr 12 23:38:37 2018 +1000
Committer: Paul King <pa...@asert.com.au>
Committed: Fri Apr 13 03:25:33 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   |  2 +-
 .../groovy/ast/LineColumnCheck_antlr2.txt         |  6 +++---
 .../groovy/ast/LineColumnCheck_antlr4.txt         |  6 +++---
 6 files changed, 33 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/12d0f443/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/12d0f443/src/test/gls/generics/GenericsTest.groovy
----------------------------------------------------------------------
diff --git a/src/test/gls/generics/GenericsTest.groovy 
b/src/test/gls/generics/GenericsTest.groovy
index 0f9e0ed..8a68145 100644
--- a/src/test/gls/generics/GenericsTest.groovy
+++ b/src/test/gls/generics/GenericsTest.groovy
@@ -576,6 +576,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/12d0f443/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/12d0f443/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 825bb63..a40cb62 100644
--- a/src/test/org/codehaus/groovy/ast/LineColumnCheck.txt
+++ b/src/test/org/codehaus/groovy/ast/LineColumnCheck.txt
@@ -256,7 +256,7 @@ class Bean {
     public value
 }
 def bean = new Bean(value:42)
-def vlaue = bean.@value
+def value = bean.@value
 
:::[AttributeExpression,(5:13),(5:24)][VariableExpression,(5:13),(5:17)][ConstantExpression,(5:19),(5:24)]
 
 ###AttributeExpression2:::

http://git-wip-us.apache.org/repos/asf/groovy/blob/12d0f443/src/test/org/codehaus/groovy/ast/LineColumnCheck_antlr2.txt
----------------------------------------------------------------------
diff --git a/src/test/org/codehaus/groovy/ast/LineColumnCheck_antlr2.txt 
b/src/test/org/codehaus/groovy/ast/LineColumnCheck_antlr2.txt
index 54e707d..15ab366 100644
--- a/src/test/org/codehaus/groovy/ast/LineColumnCheck_antlr2.txt
+++ b/src/test/org/codehaus/groovy/ast/LineColumnCheck_antlr2.txt
@@ -192,9 +192,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>>> {}

http://git-wip-us.apache.org/repos/asf/groovy/blob/12d0f443/src/test/org/codehaus/groovy/ast/LineColumnCheck_antlr4.txt
----------------------------------------------------------------------
diff --git a/src/test/org/codehaus/groovy/ast/LineColumnCheck_antlr4.txt 
b/src/test/org/codehaus/groovy/ast/LineColumnCheck_antlr4.txt
index 4eb0cb8..d7dec5b 100644
--- a/src/test/org/codehaus/groovy/ast/LineColumnCheck_antlr4.txt
+++ b/src/test/org/codehaus/groovy/ast/LineColumnCheck_antlr4.txt
@@ -192,9 +192,9 @@ Collection<? super File> c
 [ClassNode,(1:20),(1:24)]
 
 ###typeArgumentsLowerAndUpperBound:::
-Collection<? extends String,? super File> c
-:::[ClassNode,(1:1),(1:42)][GenericsType,(1:12),(1:28)][ClassNode,(1:12),(1:13)][ClassNode,(1:22),(1:28)];
-[GenericsType,(1:29),(1:41)][ClassNode,(1:29),(1:30)][ClassNode,(1:37),(1:41)]
+Map<? extends String,? super File> m
+:::[ClassNode,(1:1),(1:35)][GenericsType,(1:5),(1:21)][ClassNode,(1:5),(1:6)][ClassNode,(1:15),(1:21)];
+[GenericsType,(1:22),(1:34)][ClassNode,(1:22),(1:23)][ClassNode,(1:30),(1:34)]
 
 ###typeArgumentNested:::
 class C<Y,T extends Map<String,Map<Y,Integer>>> {}

Reply via email to