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/07/09 23:32:44 UTC
[groovy] 02/02: GROOVY-9597: update receiver after method selection
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
commit b6ca812adbbabd6c7ca311c3fb1e8269d936484c
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Thu Jul 2 17:42:24 2020 -0500
GROOVY-9597: update receiver after method selection
---
.../transform/stc/StaticTypeCheckingVisitor.java | 2 +
.../stc/ClosureParamTypeInferenceSTCTest.groovy | 52 ++++++++++++++++++++++
2 files changed, 54 insertions(+)
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 d08086a..9824cd4 100644
--- a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
+++ b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
@@ -3410,6 +3410,8 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport {
// so we store the information so that the static compiler may reuse it
call.putNodeMetaData(StaticTypesMarker.IMPLICIT_RECEIVER, data);
}
+ receiver = chosenReceiver.getType();
+
// if the object expression is a closure shared variable, we will have to perform a second pass
if (objectExpression instanceof VariableExpression) {
VariableExpression var = (VariableExpression) objectExpression;
diff --git a/src/test/groovy/transform/stc/ClosureParamTypeInferenceSTCTest.groovy b/src/test/groovy/transform/stc/ClosureParamTypeInferenceSTCTest.groovy
index 436a00e..6aa458f 100644
--- a/src/test/groovy/transform/stc/ClosureParamTypeInferenceSTCTest.groovy
+++ b/src/test/groovy/transform/stc/ClosureParamTypeInferenceSTCTest.groovy
@@ -1375,4 +1375,56 @@ method()
new C('blah', { list -> list.get(0) })
'''
}
+
+ void testGroovy9597a() {
+ assertScript '''
+ import groovy.transform.stc.*
+
+ class A {
+ def <T> void proc(Collection<T> values, @ClosureParams(FirstParam.FirstGenericType) Closure<String> block) {
+ }
+ }
+
+ class B {
+ List<Integer> list
+ void test(A a) {
+ a.proc(this.list) { it.toBigDecimal().toString() } // works
+ a.with {
+ proc(this.list) { it.toBigDecimal().toString() } // error
+ }
+ }
+ }
+
+ new B().test(new A())
+ '''
+ }
+
+ void testGroovy9597b() {
+ assertScript '''
+ import groovy.transform.stc.*
+
+ class A {
+ static A of(@DelegatesTo(A) Closure x) {
+ new A().tap {
+ x.delegate = it
+ x.call()
+ }
+ }
+ def <T> void proc(Collection<T> values, @ClosureParams(FirstParam.FirstGenericType) Closure<String> block) {
+ }
+ }
+
+ class B {
+ List<Integer> list
+ A a = A.of {
+ proc(
+ this.list,
+ { it.toBigDecimal().toString() } // Cannot find matching method java.lang.Object#toBigDecimal()
+ )
+ }
+ }
+
+ new B()
+ '''
+ }
}