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 04:17:46 UTC

[groovy] branch master updated: 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 master
in repository https://gitbox.apache.org/repos/asf/groovy.git


The following commit(s) were added to refs/heads/master by this push:
     new f0ed567  GROOVY-9058: each parameter type not correctly inferred in Object[] case (closes #921)
f0ed567 is described below

commit f0ed567f01c6077f26922bcf1ebe600e4b040f82
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 3d4dc78..a982cd3 100644
--- a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
+++ b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
@@ -3089,11 +3089,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 39c8bd0..3539e25 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']
+        '''
+    }
 }