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 2021/08/18 16:50:07 UTC

[groovy] 02/03: GROOVY-10056: Inferred parameter type of lambda expression for multi-dimensions array is not correct

This is an automated email from the ASF dual-hosted git repository.

emilles pushed a commit to branch GROOVY_3_0_X
in repository https://gitbox.apache.org/repos/asf/groovy.git

commit 9ecfe44a98bdabb6cd7c840f2326a4efcb6389f4
Author: Daniel.Sun <su...@apache.org>
AuthorDate: Mon Apr 26 20:18:56 2021 +0800

    GROOVY-10056: Inferred parameter type of lambda expression for multi-dimensions array is not correct
---
 .../transform/stc/StaticTypeCheckingVisitor.java   |  5 +--
 src/test/groovy/bugs/Groovy10056.groovy            | 44 ++++++++++++++++++++++
 2 files changed, 45 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 2f72981..7b2b1be 100644
--- a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
+++ b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
@@ -5234,10 +5234,7 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport {
                                             applyGenericsContextToParameterClass(resolvedPlaceholders, paramType));
                         }
                     }
-                    if (isVargs && lastArg && argumentType.isArray()) {
-                        argumentType = argumentType.getComponentType();
-                    }
-                    if (isVargs && lastArg && paramType.isArray()) {
+                    if (isVargs && lastArg && paramType.isArray() && !argumentType.isArray()) {
                         paramType = paramType.getComponentType();
                     }
                     argumentType = wrapTypeIfNecessary(argumentType);
diff --git a/src/test/groovy/bugs/Groovy10056.groovy b/src/test/groovy/bugs/Groovy10056.groovy
new file mode 100644
index 0000000..aa8cc89
--- /dev/null
+++ b/src/test/groovy/bugs/Groovy10056.groovy
@@ -0,0 +1,44 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package bugs
+
+import org.junit.Test
+
+import static groovy.test.GroovyAssert.assertScript
+
+final class Groovy10056  {
+    @Test
+    void test() {
+        assertScript '''\
+            @groovy.transform.CompileStatic
+            def test() {
+                String[][] strsArray = new String[][] {
+                    new String[] {'a', 'b', 'c'},
+                    new String[] {'d', 'e', 'f'}
+                }
+                Arrays.stream(strsArray)
+                            .limit(1)
+                            .forEach(strs -> {
+                                assert ['a', 'b', 'c'] == Arrays.asList(strs)
+                            })
+            }
+            test()
+        '''
+    }
+}