You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2020/05/14 07:26:30 UTC
[groovy] branch GROOVY_2_5_X updated: GROOVY-9518: STC: type check
constructor arguments like method call args (port to 2_5_X)
This is an automated email from the ASF dual-hosted git repository.
paulk pushed a commit to branch GROOVY_2_5_X
in repository https://gitbox.apache.org/repos/asf/groovy.git
The following commit(s) were added to refs/heads/GROOVY_2_5_X by this push:
new ff34ec7 GROOVY-9518: STC: type check constructor arguments like method call args (port to 2_5_X)
ff34ec7 is described below
commit ff34ec7a615f61dc8486198d8350a7525d84d1e0
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 (port to 2_5_X)
---
.../transform/stc/StaticTypeCheckingVisitor.java | 8 +++--
.../stc/ClosureParamTypeInferenceSTCTest.groovy | 37 +++++++++++++++++++++-
2 files changed, 41 insertions(+), 4 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 3248cd0..5738530 100644
--- a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
+++ b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
@@ -2165,7 +2165,6 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport {
public void visitConstructorCallExpression(ConstructorCallExpression call) {
typeCheckingContext.pushEnclosingConstructorCall(call);
try {
- super.visitConstructorCallExpression(call);
if (extension.beforeMethodCall(call)) {
extension.afterMethodCall(call);
return;
@@ -2177,6 +2176,7 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport {
ArgumentListExpression argumentList = InvocationWriter.makeArgumentList(arguments);
checkForbiddenSpreadArgument(argumentList);
+ visitMethodCallArguments(receiver, argumentList, false, null);
ClassNode[] args = getArgumentTypes(argumentList);
if (args.length > 0 &&
@@ -2189,7 +2189,6 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport {
args[0] = CLOSURE_TYPE;
}
-
MethodNode node;
if (looksLikeNamedArgConstructor(receiver, args)
&& findMethod(receiver, "<init>", DefaultGroovyMethods.init(args)).size() == 1
@@ -2209,7 +2208,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);
+ }
}
extension.afterMethodCall(call);
} finally {
diff --git a/src/test/groovy/transform/stc/ClosureParamTypeInferenceSTCTest.groovy b/src/test/groovy/transform/stc/ClosureParamTypeInferenceSTCTest.groovy
index 5b76f4f..436a00e 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) })
+ '''
+ }
}