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 15:36:37 UTC

[groovy] branch GROOVY-9518 created (now 4bc2b7d)

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.


      at 4bc2b7d  GROOVY-9518: STC: type check constructor arguments like method call args

This branch includes the following new commits:

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

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.



[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 4bc2b7db37fe00bc18fbc5293798c2e70c310651
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    | 24 +++++++++++++++++++++-
 2 files changed, 34 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..df1f1f3 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,26 @@ method()
             assert foo() == ['FEE', 'FO']
         '''
     }
+
+    void testGroovy9518() {
+        assertScript '''
+            class C {
+                C(String s, java.util.function.Consumer<List<Integer>> c) {
+                }
+            }
+
+            new C('blah', { list -> list.get(0) })
+        '''
+    }
+
+    void testGroovy9518a() {
+        assertScript '''
+            class C {
+                C(String s, java.util.function.Consumer<List<Integer>> c) {
+                }
+            }
+
+            new C('blah', { it.get(0) })
+        '''
+    }
 }