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 2020/04/21 17:20:38 UTC

[groovy] branch GROOVY-9518 updated (4bc2b7d -> 522edb0)

This is an automated email from the ASF dual-hosted git repository.

emilles pushed a change to branch GROOVY-9518
in repository https://gitbox.apache.org/repos/asf/groovy.git.


 discard 4bc2b7d  GROOVY-9518: STC: type check constructor arguments like method call args
     new 522edb0  GROOVY-9518: STC: type check constructor arguments like method call args

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (4bc2b7d)
            \
             N -- N -- N   refs/heads/GROOVY-9518 (522edb0)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../stc/ClosureParamTypeInferenceSTCTest.groovy         | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)


[groovy] 01/01: GROOVY-9518: STC: type check constructor arguments like method call args

Posted by em...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

emilles pushed a commit to branch GROOVY-9518
in repository https://gitbox.apache.org/repos/asf/groovy.git

commit 522edb050943fa70d2ade3fb7c367ec35dce43e7
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Tue Apr 21 10:33:49 2020 -0500

    GROOVY-9518: STC: type check constructor arguments like method call args
---
 .../transform/stc/StaticTypeCheckingVisitor.java   | 16 +++++++---
 .../stc/ClosureParamTypeInferenceSTCTest.groovy    | 37 +++++++++++++++++++++-
 2 files changed, 47 insertions(+), 6 deletions(-)

diff --git a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
index fec7971..f33fb0c 100644
--- a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
+++ b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
@@ -2185,18 +2185,21 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport {
 
     @Override
     public void visitConstructorCallExpression(final ConstructorCallExpression call) {
-        super.visitConstructorCallExpression(call);
         if (extension.beforeMethodCall(call)) {
             extension.afterMethodCall(call);
             return;
         }
-        ClassNode receiver = call.isThisCall() ? typeCheckingContext.getEnclosingClassNode() :
-                call.isSuperCall() ? typeCheckingContext.getEnclosingClassNode().getSuperClass() : call.getType();
+        ClassNode receiver = call.getType();
+        if (call.isThisCall()) {
+            receiver = typeCheckingContext.getEnclosingClassNode();
+        } else if (call.isSuperCall()) {
+            receiver = typeCheckingContext.getEnclosingClassNode().getSuperClass();
+        }
         Expression arguments = call.getArguments();
-
         ArgumentListExpression argumentList = InvocationWriter.makeArgumentList(arguments);
 
         checkForbiddenSpreadArgument(argumentList);
+        visitMethodCallArguments(receiver, argumentList, false, null);
 
         ClassNode[] args = getArgumentTypes(argumentList);
         if (args.length > 0 &&
@@ -2226,7 +2229,10 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport {
             } else {
                 typeCheckMethodsWithGenericsOrFail(receiver, args, node, call);
             }
-            if (node != null) storeTargetMethod(call, node);
+            if (node != null) {
+                storeTargetMethod(call, node);
+                visitMethodCallArguments(receiver, argumentList, true, node);
+            }
         }
 
         // GROOVY-9327: check for AIC in STC method with non-STC enclosing class
diff --git a/src/test/groovy/transform/stc/ClosureParamTypeInferenceSTCTest.groovy b/src/test/groovy/transform/stc/ClosureParamTypeInferenceSTCTest.groovy
index 3539e25..373b11f 100644
--- a/src/test/groovy/transform/stc/ClosureParamTypeInferenceSTCTest.groovy
+++ b/src/test/groovy/transform/stc/ClosureParamTypeInferenceSTCTest.groovy
@@ -545,7 +545,7 @@ import groovy.transform.stc.ClosureParams
             assert sum == 110
         '''
     }
-    
+
     void testInferenceForDGM_upto() {
         assertScript '''
             BigDecimal sum = 0
@@ -1340,4 +1340,39 @@ method()
             assert foo() == ['FEE', 'FO']
         '''
     }
+
+    void testGroovy9518() {
+        assertScript '''
+            class C {
+                C(String s, Comparable<List<Integer>> c) {
+                }
+            }
+
+            new C('blah', { list -> list.get(0) })
+        '''
+    }
+
+    void testGroovy9518a() {
+        assertScript '''
+            class C {
+                C(String s, Comparable<List<Integer>> c) {
+                }
+            }
+
+            new C('blah', { it.get(0) })
+        '''
+    }
+
+    void testGroovy9518b() {
+        assertScript '''
+            import groovy.transform.stc.*
+
+            class C {
+                C(String s, @ClosureParams(value=SimpleType, options='java.util.List') Closure<Integer> c) {
+                }
+            }
+
+            new C('blah', { list -> list.get(0) })
+        '''
+    }
 }