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 2022/01/31 22:46:41 UTC

[groovy] branch GROOVY_2_5_X updated (5b0ce95 -> ff8acdb)

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

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


    from 5b0ce95  GROOVY-7160: fix test case
     new 307fff2  GROOVY-8638: erase generics for no-signature fields/methods like bridges
     new ff8acdb  GROOVY-8652: add test case

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:
 .../ast/decompiled/MemberSignatureParser.java      | 10 ++++-
 .../{Groovy8337Bug.groovy => Groovy8652.groovy}    | 50 ++++++++++++++--------
 .../groovy/transform/stc/GenericsSTCTest.groovy    | 21 ++++++++-
 .../groovy/ast/decompiled/AsmDecompilerTest.groovy | 32 ++++++--------
 .../ast/decompiled/AsmDecompilerTestData.java      |  1 +
 5 files changed, 76 insertions(+), 38 deletions(-)
 copy src/test/groovy/bugs/{Groovy8337Bug.groovy => Groovy8652.groovy} (60%)

[groovy] 02/02: GROOVY-8652: add test case

Posted by em...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit ff8acdb406c78a2bfa1d6b11be0f67cd24160be4
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Mon Jan 31 16:28:31 2022 -0600

    GROOVY-8652: add test case
---
 src/test/groovy/bugs/Groovy8652.groovy | 68 ++++++++++++++++++++++++++++++++++
 1 file changed, 68 insertions(+)

diff --git a/src/test/groovy/bugs/Groovy8652.groovy b/src/test/groovy/bugs/Groovy8652.groovy
new file mode 100644
index 0000000..487660a
--- /dev/null
+++ b/src/test/groovy/bugs/Groovy8652.groovy
@@ -0,0 +1,68 @@
+/*
+ *  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 groovy.bugs
+
+import org.junit.Test
+
+import static groovy.test.GroovyAssert.assertScript
+
+final class Groovy8652 {
+
+    @Test
+    void testPutMapValue() {
+        assertScript '''
+            import groovy.transform.CompileStatic
+
+            @CompileStatic
+            class C {
+                final Map<?,?> map = [:]
+            }
+
+            @CompileStatic
+            void test() {
+                def obj = new C()
+                obj.map.put('key','value')
+                assert obj.map.key == 'value'
+            }
+
+            test()
+        '''
+    }
+
+    @Test
+    void testSetMapValue() {
+        assertScript '''
+            import groovy.transform.CompileStatic
+
+            @CompileStatic
+            class C {
+                final Map<?,?> map = [:]
+            }
+
+            @CompileStatic
+            void test() {
+                def obj = new C()
+                obj.map.key = 'value'
+                assert obj.map.key == 'value'
+            }
+
+            test()
+        '''
+    }
+}

[groovy] 01/02: GROOVY-8638: erase generics for no-signature fields/methods like bridges

Posted by em...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 307fff24d91205d45318928b50480606272eb023
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Tue Jun 1 11:01:02 2021 -0500

    GROOVY-8638: erase generics for no-signature fields/methods like bridges
    
    Conflicts:
    	src/main/java/org/codehaus/groovy/ast/decompiled/MemberSignatureParser.java
    	src/test/groovy/transform/stc/GenericsSTCTest.groovy
---
 .../ast/decompiled/MemberSignatureParser.java      | 10 ++++++-
 .../groovy/transform/stc/GenericsSTCTest.groovy    | 21 ++++++++++++--
 .../groovy/ast/decompiled/AsmDecompilerTest.groovy | 32 ++++++++++------------
 .../ast/decompiled/AsmDecompilerTestData.java      |  1 +
 4 files changed, 43 insertions(+), 21 deletions(-)

diff --git a/src/main/java/org/codehaus/groovy/ast/decompiled/MemberSignatureParser.java b/src/main/java/org/codehaus/groovy/ast/decompiled/MemberSignatureParser.java
index dd73433..7670329 100644
--- a/src/main/java/org/codehaus/groovy/ast/decompiled/MemberSignatureParser.java
+++ b/src/main/java/org/codehaus/groovy/ast/decompiled/MemberSignatureParser.java
@@ -27,6 +27,7 @@ import org.codehaus.groovy.ast.MethodNode;
 import org.codehaus.groovy.ast.Parameter;
 import org.codehaus.groovy.ast.expr.ConstantExpression;
 import org.codehaus.groovy.ast.stmt.ReturnStatement;
+import org.codehaus.groovy.ast.tools.GenericsUtils;
 import org.objectweb.asm.Type;
 import org.objectweb.asm.signature.SignatureReader;
 import org.objectweb.asm.signature.SignatureVisitor;
@@ -96,6 +97,11 @@ class MemberSignatureParser {
             };
             new SignatureReader(method.signature).accept(v);
             typeParameters = v.getTypeParameters();
+        } else {
+            returnType[0] = GenericsUtils.nonGeneric(returnType[0]);
+            for (int i = 0, n = parameterTypes.length; i < n; i += 1) {
+                parameterTypes[i] = GenericsUtils.nonGeneric(parameterTypes[i]);
+            }
         }
 
         Parameter[] parameters = new Parameter[parameterTypes.length];
@@ -165,9 +171,11 @@ class MemberSignatureParser {
                     type[0] = applyErasure(result, type[0]);
                 }
             });
+        } else {
+            // ex: java.util.Collections#EMPTY_LIST/EMPTY_MAP/EMPTY_SET
+            type[0] = GenericsUtils.nonGeneric(type[0]);
         }
         ConstantExpression value = field.value == null ? null : new ConstantExpression(field.value);
         return new FieldNode(field.fieldName, field.accessModifiers, type[0], owner, value);
     }
 }
-
diff --git a/src/test/groovy/transform/stc/GenericsSTCTest.groovy b/src/test/groovy/transform/stc/GenericsSTCTest.groovy
index 7f2d341..2050c32 100644
--- a/src/test/groovy/transform/stc/GenericsSTCTest.groovy
+++ b/src/test/groovy/transform/stc/GenericsSTCTest.groovy
@@ -171,7 +171,24 @@ class GenericsSTCTest extends StaticTypeCheckingTestCase {
         '''
     }
 
-    void testDiamondInferrenceFromConstructor() {
+    // GROOVY-8638
+    void testReturnTypeInferenceWithMethodGenerics17() {
+        assertScript '''
+            @Grab('com.google.guava:guava:30.1.1-jre')
+            import com.google.common.collect.*
+
+            ListMultimap<String, Integer> mmap = ArrayListMultimap.create()
+
+            Map<String, Collection<Integer>> map = mmap.asMap()
+            Set<Map.Entry<String, Collection<Integer>>> set = map.entrySet()
+            Iterator<Map.Entry<String, Collection<Integer>>> it = set.iterator()
+            while (it.hasNext()) { Map.Entry<String, Collection<Integer>> entry = it.next()
+                Collection<Integer> values = entry.value
+            }
+        '''
+    }
+
+    void testDiamondInferrenceFromConstructor1() {
         assertScript '''
             Set< Long > s2 = new HashSet<>()
         '''
@@ -1803,7 +1820,7 @@ class GenericsSTCTest extends StaticTypeCheckingTestCase {
     // GROOVY-6760
     void testGenericsAtMethodLevelWithGenericsInTypeOfGenericType() {
         assertScript '''
-            @Grab(group='com.netflix.rxjava', module='rxjava-core', version='0.18.1')
+            @Grab('com.netflix.rxjava:rxjava-core:0.18.1')
             import rx.Observable
             import java.util.concurrent.Callable
 
diff --git a/src/test/org/codehaus/groovy/ast/decompiled/AsmDecompilerTest.groovy b/src/test/org/codehaus/groovy/ast/decompiled/AsmDecompilerTest.groovy
index 0a5b1c0..dd8f9a6 100644
--- a/src/test/org/codehaus/groovy/ast/decompiled/AsmDecompilerTest.groovy
+++ b/src/test/org/codehaus/groovy/ast/decompiled/AsmDecompilerTest.groovy
@@ -28,7 +28,7 @@ import org.codehaus.groovy.control.ClassNodeResolver
 import org.codehaus.groovy.control.CompilationUnit
 import org.objectweb.asm.Opcodes
 
-class AsmDecompilerTest extends TestCase {
+final class AsmDecompilerTest extends TestCase {
 
     void "test decompile class"() {
         ClassNode node = decompile()
@@ -198,13 +198,9 @@ class AsmDecompilerTest extends TestCase {
         assert !anno.isTargetAllowed(AnnotationNode.LOCAL_VARIABLE_TARGET)
     }
 
-    static enum TestEnum {
-        SOURCE, CLASS, RUNTIME
-    }
-
     void "test enum field"() {
-        def node = decompile(TestEnum.name).plainNodeReference
-        for (s in ['SOURCE', 'CLASS', 'RUNTIME']) {
+        def node = decompile(SomeEnum.name).plainNodeReference
+        for (s in ['FOO', 'BAR']) {
             def field = node.getDeclaredField(s)
             assert field
             assert field.type == node
@@ -277,10 +273,14 @@ class AsmDecompilerTest extends TestCase {
         assert field.type.toString() == 'V -> java.lang.RuntimeException'
     }
 
-    static class SomeInnerclass {}
-
     void "test static inner class"() {
-        assert (decompile(SomeInnerclass.name).modifiers & Opcodes.ACC_STATIC) != 0
+        ClassNode cn = decompile(AsmDecompilerTestData.InnerStatic.name)
+        assert (cn.modifiers & Opcodes.ACC_STATIC) != 0
+    }
+
+    void "test static inner with dollar"() {
+        ClassNode cn = decompile(AsmDecompilerTestData.Inner$WithDollar.name)
+        assert (cn.modifiers & Opcodes.ACC_STATIC) != 0
     }
 
     void "test static inner classes with same name"() {
@@ -297,10 +297,6 @@ class AsmDecompilerTest extends TestCase {
         assert (cn.modifiers & Opcodes.ACC_ABSTRACT) == 0
     }
 
-    void "test static inner with dollar"() {
-        assert (decompile(AsmDecompilerTestData.Inner$WithDollar.name).modifiers & Opcodes.ACC_STATIC) != 0
-    }
-
     void "test inner classes with same name"() {
         ClassNode cn = decompile(Groovy8632Abstract.InnerBuilder.name)
         assert (cn.modifiers & Opcodes.ACC_STATIC) == 0
@@ -338,14 +334,14 @@ class AsmDecompilerTest extends TestCase {
         assert asmType.genericsTypes.collect { it.name } == jvmType.genericsTypes.collect { it.name }
     }
 
-    private static ClassNode decompile(String cls = AsmDecompilerTestData.name) {
-        def classFileName = cls.replace('.', '/') + '.class'
+    //--------------------------------------------------------------------------
+
+    private static ClassNode decompile(String className = AsmDecompilerTestData.name) {
+        def classFileName = className.replace('.', '/') + '.class'
         def resource = AsmDecompilerTest.classLoader.getResource(classFileName)
         def stub = AsmDecompiler.parseClass(resource)
 
         def unit = new CompilationUnit(new GroovyClassLoader(AsmDecompilerTest.classLoader))
         return new DecompiledClassNode(stub, new AsmReferenceResolver(new ClassNodeResolver(), unit))
     }
-
 }
-
diff --git a/src/test/org/codehaus/groovy/ast/decompiled/AsmDecompilerTestData.java b/src/test/org/codehaus/groovy/ast/decompiled/AsmDecompilerTestData.java
index e816543..fcd81ff 100644
--- a/src/test/org/codehaus/groovy/ast/decompiled/AsmDecompilerTestData.java
+++ b/src/test/org/codehaus/groovy/ast/decompiled/AsmDecompilerTestData.java
@@ -73,6 +73,7 @@ public class AsmDecompilerTestData<T extends List<? super T>, V> extends SuperCl
     public List<T> genericField;
 
     class Inner<X> {}
+    static class InnerStatic {}
     static class Inner$WithDollar {}
 
     static <T extends List<? super T>> AsmDecompilerTestData<T, Integer>.Inner<String> returnInner() { return null; }