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 2019/05/04 05:15:34 UTC
[groovy] 03/03: GROOVY-9058: each parameter type not correctly
inferred in Object[] case (closes #921)
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 4bde222a4e2a69a47afc73ea5a52b6087215a9d3
Author: Paul King <pa...@asert.com.au>
AuthorDate: Fri May 3 20:50:14 2019 +1000
GROOVY-9058: each parameter type not correctly inferred in Object[] case (closes #921)
---
.../groovy/transform/stc/StaticTypeCheckingVisitor.java | 6 +-----
.../transform/stc/ClosureParamTypeInferenceSTCTest.groovy | 15 +++++++++++++++
2 files changed, 16 insertions(+), 5 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 9c8b763..922c7ce 100644
--- a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
+++ b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
@@ -2945,11 +2945,7 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport {
}
boolean lastArg = i == length - 1;
- if (lastArg && inferredType.isArray()) {
- if (inferredType.getComponentType().equals(originType)) {
- inferredType = originType;
- }
- } else if (!typeCheckMethodArgumentWithGenerics(originType, inferredType, lastArg)) {
+ if (!typeCheckMethodArgumentWithGenerics(originType, inferredType, lastArg)) {
addError("Expected parameter of type " + inferredType.toString(false) + " but got " + originType.toString(false), closureParam.getType());
}
diff --git a/src/test/groovy/transform/stc/ClosureParamTypeInferenceSTCTest.groovy b/src/test/groovy/transform/stc/ClosureParamTypeInferenceSTCTest.groovy
index 0c0ba80..5b76f4f 100644
--- a/src/test/groovy/transform/stc/ClosureParamTypeInferenceSTCTest.groovy
+++ b/src/test/groovy/transform/stc/ClosureParamTypeInferenceSTCTest.groovy
@@ -1325,4 +1325,19 @@ def method() {
method()
'''
}
+
+ void testGroovy9058() {
+ assertScript '''
+ List<Object[]> bar() { [['fee', 'fi'] as Object[], ['fo', 'fum'] as Object[]] }
+
+ def foo() {
+ def result = []
+ List<Object[]> bar = bar()
+ bar.each { row -> result << row[0].toString().toUpperCase() }
+ result
+ }
+
+ assert foo() == ['FEE', 'FO']
+ '''
+ }
}