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 2023/01/12 21:33:22 UTC

[groovy] branch GROOVY_3_0_X updated (f58873c34b -> 2d7fc65d1d)

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

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


    from f58873c34b GROOVY-10339, GROOVY-10633, GROOVY-10890: STC: type parameter resolution
     new 21515c9efe GROOVY-10062: STC: combine variadic method return type inference checks
     new 2d7fc65d1d GROOVY-10785: ASM 9.4

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 build.gradle                                       |  2 +-
 .../transform/stc/StaticTypeCheckingVisitor.java   | 21 +++++------
 src/test/groovy/bugs/Groovy10056.groovy            | 44 ----------------------
 .../groovy/transform/stc/GenericsSTCTest.groovy    |  1 -
 4 files changed, 10 insertions(+), 58 deletions(-)
 delete mode 100644 src/test/groovy/bugs/Groovy10056.groovy


[groovy] 02/02: GROOVY-10785: ASM 9.4

Posted by em...@apache.org.
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 2d7fc65d1d6540cfb58b045a1818e8dcb035ac41
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Thu Jan 12 15:32:53 2023 -0600

    GROOVY-10785: ASM 9.4
---
 build.gradle | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/build.gradle b/build.gradle
index b4ecda10c7..a844523bcb 100644
--- a/build.gradle
+++ b/build.gradle
@@ -123,7 +123,7 @@ configurations {
 
 ext {
     antVersion = '1.10.12'
-    asmVersion = '9.3'
+    asmVersion = '9.4'
     antlrVersion = '2.7.7'
     antlr4Version = '4.9.0'
     bridgerVersion = '1.6.Final'


[groovy] 01/02: GROOVY-10062: STC: combine variadic method return type inference checks

Posted by em...@apache.org.
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 21515c9efe4970075389aee201143d41c2f8d2ad
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Thu Jan 12 15:28:57 2023 -0600

    GROOVY-10062: STC: combine variadic method return type inference checks
    
    3_0_X backport
---
 .../transform/stc/StaticTypeCheckingVisitor.java   | 21 +++++------
 src/test/groovy/bugs/Groovy10056.groovy            | 44 ----------------------
 .../groovy/transform/stc/GenericsSTCTest.groovy    |  1 -
 3 files changed, 9 insertions(+), 57 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 31c1d6a851..38ad511812 100644
--- a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
+++ b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
@@ -5383,19 +5383,19 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport {
                 }
             } else if (nParameters > 0) { // resolve type parameters from call arguments
                 List<Expression> expressions = InvocationWriter.makeArgumentList(arguments).getExpressions();
+                int nArguments = expressions.size();
                 boolean isVargs = isVargs(parameters);
-                if (expressions.size() >= nParameters) {
-                    for (int i = 0; i < nParameters; i += 1) {
+                if (isVargs ? nArguments >= nParameters-1 : nArguments == nParameters) {
+                    for (int i = 0; i < nArguments; i += 1) {
                         if (isNullConstant(expressions.get(i)))
                             continue; // GROOVY-9984: skip null
-                        boolean lastArg = (i == nParameters - 1);
-                        ClassNode paramType = parameters[i].getType();
                         ClassNode argumentType = getDeclaredOrInferredType(expressions.get(i));
-                        while (paramType.isArray() && argumentType.isArray()) {
-                            paramType = paramType.getComponentType();
-                            argumentType = argumentType.getComponentType();
-                        }
-                        if (isUsingGenericsOrIsArrayUsingGenerics(paramType)) {
+                        ClassNode paramType = parameters[Math.min(i, nParameters-1)].getType();
+                        if (GenericsUtils.hasUnresolvedGenerics(paramType)) {
+                            // if supplying array param with multiple arguments or single non-array argument, infer using element type
+                            if (isVargs && (i >= nParameters || (i == nParameters-1 && (nArguments > nParameters || !argumentType.isArray())))) {
+                                paramType = paramType.getComponentType();
+                            }
                             if (argumentType.isDerivedFrom(CLOSURE_TYPE)) {
                                 MethodNode sam = findSAM(paramType);
                                 if (sam != null) { // implicit closure coercion in action!
@@ -5404,9 +5404,6 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport {
                                                     applyGenericsContextToParameterClass(resolvedPlaceholders, paramType));
                                 }
                             }
-                            if (isVargs && lastArg && paramType.isArray() && !argumentType.isArray()) {
-                                paramType = paramType.getComponentType();
-                            }
                             Map<GenericsTypeName, GenericsType> connections = new HashMap<>();
                             extractGenericsConnections(connections, wrapTypeIfNecessary(argumentType), paramType);
                             connections.forEach((name, type) -> resolvedPlaceholders.merge(name, type, StaticTypeCheckingSupport::getCombinedGenericsType));
diff --git a/src/test/groovy/bugs/Groovy10056.groovy b/src/test/groovy/bugs/Groovy10056.groovy
deleted file mode 100644
index aa8cc89ed5..0000000000
--- a/src/test/groovy/bugs/Groovy10056.groovy
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- *  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()
-        '''
-    }
-}
diff --git a/src/test/groovy/transform/stc/GenericsSTCTest.groovy b/src/test/groovy/transform/stc/GenericsSTCTest.groovy
index 873eb4f1f9..458fd9e5c0 100644
--- a/src/test/groovy/transform/stc/GenericsSTCTest.groovy
+++ b/src/test/groovy/transform/stc/GenericsSTCTest.groovy
@@ -216,7 +216,6 @@ class GenericsSTCTest extends StaticTypeCheckingTestCase {
     }
 
     // GROOVY-10062
-    @NotYetImplemented
     void testReturnTypeInferenceWithMethodGenerics2() {
         assertScript '''
             def <T> T m(T t, ... zeroOrMore) {