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/07/01 15:57:54 UTC

[groovy] branch master updated: minor edits

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

emilles 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 7eb6a1bae7 minor edits
7eb6a1bae7 is described below

commit 7eb6a1bae73a09c8afee62ddb3652ec935522c95
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Fri Jul 1 10:57:24 2022 -0500

    minor edits
---
 .../ast/decompiled/FormalParameterParser.java      |  38 +++---
 .../stc/ClosureParamTypeInferenceSTCTest.groovy    | 139 +++++++++++----------
 .../classgen/asm/BinaryOperationsTest.groovy       |  41 +++---
 3 files changed, 121 insertions(+), 97 deletions(-)

diff --git a/src/main/java/org/codehaus/groovy/ast/decompiled/FormalParameterParser.java b/src/main/java/org/codehaus/groovy/ast/decompiled/FormalParameterParser.java
index 2e7b1ebf0b..55de8532cb 100644
--- a/src/main/java/org/codehaus/groovy/ast/decompiled/FormalParameterParser.java
+++ b/src/main/java/org/codehaus/groovy/ast/decompiled/FormalParameterParser.java
@@ -29,33 +29,40 @@ import java.util.List;
 import static org.codehaus.groovy.control.CompilerConfiguration.ASM_API_VERSION;
 
 abstract class FormalParameterParser extends SignatureVisitor {
-    private final AsmReferenceResolver resolver;
+
     private String currentTypeParameter;
-    private final List<ClassNode> parameterBounds = new ArrayList<ClassNode>();
-    private final List<GenericsType> typeParameters = new ArrayList<GenericsType>();
+    private final List<ClassNode> parameterBounds = new ArrayList<>();
+    private final List<GenericsType> typeParameters = new ArrayList<>();
+
+    private final AsmReferenceResolver resolver;
 
-    public FormalParameterParser(AsmReferenceResolver resolver) {
+    public FormalParameterParser(final AsmReferenceResolver resolver) {
         super(ASM_API_VERSION);
         this.resolver = resolver;
     }
 
-    @Override
-    public void visitFormalTypeParameter(String name) {
-        flushTypeParameter();
-        currentTypeParameter = name;
-    }
-
     protected void flushTypeParameter() {
         if (currentTypeParameter != null) {
             ClassNode ref = Java8.configureTypeVariableReference(currentTypeParameter);
-            ClassNode[] boundNodes = parameterBounds.toArray(ClassNode.EMPTY_ARRAY);
-            typeParameters.add(Java8.configureTypeVariableDefinition(ref, boundNodes));
+            ClassNode[] theBoundTypes = parameterBounds.toArray(ClassNode.EMPTY_ARRAY);
+            typeParameters.add(Java8.configureTypeVariableDefinition(ref, theBoundTypes));
 
-            currentTypeParameter = null;
             parameterBounds.clear();
+            currentTypeParameter = null;
         }
     }
 
+    public GenericsType[] getTypeParameters() {
+        flushTypeParameter();
+        return typeParameters.toArray(GenericsType.EMPTY_ARRAY);
+    }
+
+    @Override
+    public void visitFormalTypeParameter(final String name) {
+        flushTypeParameter();
+        currentTypeParameter = name;
+    }
+
     @Override
     public SignatureVisitor visitClassBound() {
         return new TypeSignatureParser(resolver) {
@@ -70,9 +77,4 @@ abstract class FormalParameterParser extends SignatureVisitor {
     public SignatureVisitor visitInterfaceBound() {
         return visitClassBound();
     }
-
-    public GenericsType[] getTypeParameters() {
-        flushTypeParameter();
-        return typeParameters.toArray(GenericsType.EMPTY_ARRAY);
-    }
 }
diff --git a/src/test/groovy/transform/stc/ClosureParamTypeInferenceSTCTest.groovy b/src/test/groovy/transform/stc/ClosureParamTypeInferenceSTCTest.groovy
index b7ea2cb3a6..975e1c8602 100644
--- a/src/test/groovy/transform/stc/ClosureParamTypeInferenceSTCTest.groovy
+++ b/src/test/groovy/transform/stc/ClosureParamTypeInferenceSTCTest.groovy
@@ -580,30 +580,30 @@ class ClosureParamTypeInferenceSTCTest extends StaticTypeCheckingTestCase {
 
     void testInferenceForDGM_dropWhileOnIterable() {
         assertScript '''
-        assert (0..10).dropWhile { it<5 } == (5..10)
-        assert (0..10).dropWhile { int i -> i<5 } == (5..10)
+            assert (0..10).dropWhile { it<5 } == (5..10)
+            assert (0..10).dropWhile { int i -> i<5 } == (5..10)
         '''
     }
 
     void testInferenceForDGM_dropWhileOnList() {
         assertScript '''
-        assert [0,1,2,3,4,5,6,7,8,9,10].dropWhile { it<5 } == [5,6,7,8,9,10]
-        assert [0,1,2,3,4,5,6,7,8,9,10].dropWhile { int i -> i<5 } == [5,6,7,8,9,10]
+            assert [0,1,2,3,4,5,6,7,8,9,10].dropWhile { it<5 } == [5,6,7,8,9,10]
+            assert [0,1,2,3,4,5,6,7,8,9,10].dropWhile { int i -> i<5 } == [5,6,7,8,9,10]
         '''
     }
 
     void testInferenceForDGM_dropWhileOnIterator() {
         assertScript '''
-        assert [0,1,2,3,4,5,6,7,8,9,10].iterator().dropWhile { it<5 } as List == [5,6,7,8,9,10]
-        assert [0,1,2,3,4,5,6,7,8,9,10].iterator().dropWhile { int i -> i<5 } as List == [5,6,7,8,9,10]
+            assert [0,1,2,3,4,5,6,7,8,9,10].iterator().dropWhile { it<5 } as List == [5,6,7,8,9,10]
+            assert [0,1,2,3,4,5,6,7,8,9,10].iterator().dropWhile { int i -> i<5 } as List == [5,6,7,8,9,10]
         '''
     }
 
     void testInferenceForDGM_dropWhileOnArray() {
         assertScript '''
-        Integer[] array = [0,1,2,3,4,5,6,7,8,9,10]
-        assert array.iterator().dropWhile { it<5 } as List == [5,6,7,8,9,10]
-        assert array.iterator().dropWhile { int i -> i<5 } as List == [5,6,7,8,9,10]
+            Integer[] array = [0,1,2,3,4,5,6,7,8,9,10]
+            assert array.iterator().dropWhile { it<5 } as List == [5,6,7,8,9,10]
+            assert array.iterator().dropWhile { int i -> i<5 } as List == [5,6,7,8,9,10]
         '''
     }
 
@@ -637,13 +637,15 @@ class ClosureParamTypeInferenceSTCTest extends StaticTypeCheckingTestCase {
         '''
     }
     void testInferenceForDGM_eachWithIndexOnRecursiveIterable() { // GROOVY-10651
-        assertScript '''
-            void proc(groovy.transform.stc.TreeNode node) {
-                node.eachWithIndex { child, index ->
-                    proc(child) // recurse
+        ['', '<?>'].each { args ->
+            assertScript """
+                void proc(groovy.transform.stc.TreeNode$args node) {
+                    node.eachWithIndex { child, index ->
+                        proc(child) // recurse
+                    }
                 }
-            }
-        '''
+            """
+        }
     }
 
     void testInferenceForDGM_everyOnIterable() {
@@ -1049,18 +1051,16 @@ class ClosureParamTypeInferenceSTCTest extends StaticTypeCheckingTestCase {
 
     void testDGM_sortOnMap() {
         assertScript '''
-        def map = [a:5, b:3, c:6, d:4].sort { a, b -> a.value <=> b.value }
-        assert map == [b:3, d:4, a:5, c:6]
+            def map = [a:5, b:3, c:6, d:4].sort { a, b -> a.value <=> b.value }
+            assert map == [b:3, d:4, a:5, c:6]
         '''
-
         assertScript '''
-        def map = [a:5, b:3, c:6, d:4].sort { a -> a.value }
-        assert map == [b:3, d:4, a:5, c:6]
+            def map = [a:5, b:3, c:6, d:4].sort { a -> a.value }
+            assert map == [b:3, d:4, a:5, c:6]
         '''
-
         assertScript '''
-        def map = [a:5, b:3, c:6, d:4].sort { it.value }
-        assert map == [b:3, d:4, a:5, c:6]
+            def map = [a:5, b:3, c:6, d:4].sort { it.value }
+            assert map == [b:3, d:4, a:5, c:6]
         '''
     }
 
@@ -1072,42 +1072,45 @@ class ClosureParamTypeInferenceSTCTest extends StaticTypeCheckingTestCase {
 
     void testDGM_takeWhileOnIterable() {
         assertScript '''
-        class AbcIterable implements Iterable<String>  {
-           Iterator<String>  iterator() { "abc".iterator() }
-       }
-       def abc = new AbcIterable()
-       assert abc.takeWhile{ it < 'b' } == ['a']
-       assert abc.takeWhile{ it <= 'b' } == ['a', 'b']
-'''
+            class AbcIterable implements Iterable<String>  {
+                Iterator<String>  iterator() { "abc".iterator() }
+            }
+            def abc = new AbcIterable()
+            assert abc.takeWhile{ it < 'b' } == ['a']
+            assert abc.takeWhile{ it <= 'b' } == ['a', 'b']
+        '''
     }
     void testDGM_takeWhileOnIterator() {
         assertScript '''
-        class AbcIterable implements Iterable<String>  {
-           Iterator<String>  iterator() { "abc".iterator() }
-       }
-       def abc = new AbcIterable()
-       assert abc.iterator().takeWhile{ it < 'b' }.collect() == ['a']
-       assert abc.iterator().takeWhile{ it <= 'b' }.collect() == ['a', 'b']
-'''
+            class AbcIterable implements Iterable<String>  {
+                Iterator<String>  iterator() { "abc".iterator() }
+            }
+            def abc = new AbcIterable()
+            assert abc.iterator().takeWhile{ it < 'b' }.collect() == ['a']
+            assert abc.iterator().takeWhile{ it <= 'b' }.collect() == ['a', 'b']
+        '''
     }
     void testDGM_takeWhileOnList() {
         assertScript '''
-       def abc = ['a','b','c']
-       assert abc.iterator().takeWhile{ it < 'b' }.collect() == ['a']
-       assert abc.iterator().takeWhile{ it <= 'b' }.collect() == ['a', 'b']'''
+            def abc = ['a','b','c']
+            assert abc.iterator().takeWhile{ it < 'b' }.collect() == ['a']
+            assert abc.iterator().takeWhile{ it <= 'b' }.collect() == ['a', 'b']
+        '''
     }
     void testDGM_takeWhileOnArray() {
         assertScript '''
             String[] abc = ['a','b','c']
             assert abc.iterator().takeWhile{ it < 'b' }.collect() == ['a']
-            assert abc.iterator().takeWhile{ it <= 'b' }.collect() == ['a', 'b']'''
+            assert abc.iterator().takeWhile{ it <= 'b' }.collect() == ['a', 'b']
+        '''
     }
     void testDGM_takeWhileOnMap() {
         assertScript '''
             def shopping = [milk:1, bread:2, chocolate:3]
             assert shopping.takeWhile{ it.key.size() < 6 } == [milk:1, bread:2]
             assert shopping.takeWhile{ it.value % 2 } == [milk:1]
-            assert shopping.takeWhile{ k, v -> k.size() + v <= 7 } == [milk:1, bread:2]'''
+            assert shopping.takeWhile{ k, v -> k.size() + v <= 7 } == [milk:1, bread:2]
+        '''
     }
 
     void testDGM_times() {
@@ -1121,35 +1124,41 @@ class ClosureParamTypeInferenceSTCTest extends StaticTypeCheckingTestCase {
 
     void testDGM_unique() {
         assertScript '''
-       def orig = [1, 3, 4, 5]
-       def uniq = orig.unique(false) { it % 2 }
-       assert orig == [1, 3, 4, 5]
-       assert uniq == [1, 4]'''
-
-       assertScript '''def orig = [2, 3, 3, 4]
-       def uniq = orig.unique(false) { a, b -> a <=> b }
-       assert orig == [2, 3, 3, 4]
-       assert uniq == [2, 3, 4]'''
+            def orig = [1, 3, 4, 5]
+            def uniq = orig.unique(false) { it % 2 }
+            assert orig == [1, 3, 4, 5]
+            assert uniq == [1, 4]
+        '''
+        assertScript '''
+            def orig = [2, 3, 3, 4]
+            def uniq = orig.unique(false) { a, b -> a <=> b }
+            assert orig == [2, 3, 3, 4]
+            assert uniq == [2, 3, 4]
+        '''
     }
     void testDGM_uniqueOnCollection() {
         assertScript '''
-       def orig = [1, 3, 4, 5]
-       def uniq = orig.unique { it % 2 }
-       assert uniq == [1, 4]'''
-
-       assertScript '''def orig = [2, 3, 3, 4]
-       def uniq = orig.unique { a, b -> a <=> b }
-       assert uniq == [2, 3, 4]'''
+            def orig = [1, 3, 4, 5]
+            def uniq = orig.unique { it % 2 }
+            assert uniq == [1, 4]
+        '''
+        assertScript '''
+            def orig = [2, 3, 3, 4]
+            def uniq = orig.unique { a, b -> a <=> b }
+            assert uniq == [2, 3, 4]
+        '''
     }
     void testDGM_uniqueOnIterator() {
         assertScript '''
-       def orig = [1, 3, 4, 5].iterator()
-       def uniq = orig.unique { it % 2 }.collect()
-       assert uniq == [1, 4]'''
-
-       assertScript '''def orig = [2, 3, 3, 4].iterator()
-       def uniq = orig.unique { a, b -> a <=> b }.collect()
-       assert uniq == [2, 3, 4]'''
+            def orig = [1, 3, 4, 5].iterator()
+            def uniq = orig.unique { it % 2 }.collect()
+            assert uniq == [1, 4]
+        '''
+        assertScript '''
+            def orig = [2, 3, 3, 4].iterator()
+            def uniq = orig.unique { a, b -> a <=> b }.collect()
+            assert uniq == [2, 3, 4]
+        '''
     }
 
     void testDGM_anyOnMap() {
diff --git a/src/test/org/codehaus/groovy/classgen/asm/BinaryOperationsTest.groovy b/src/test/org/codehaus/groovy/classgen/asm/BinaryOperationsTest.groovy
index a7ce4820f7..6255532e6f 100644
--- a/src/test/org/codehaus/groovy/classgen/asm/BinaryOperationsTest.groovy
+++ b/src/test/org/codehaus/groovy/classgen/asm/BinaryOperationsTest.groovy
@@ -104,32 +104,45 @@ class BinaryOperationsTest extends AbstractBytecodeTestCase {
 
     void testCharXor() {
         if (config.indyEnabled) return;
-        assert compile("""
-            int i = ('a' as char) ^ ('b' as char) 
-        """).hasStrictSequence ([
-            "IXOR"
+        assert compile('''
+            int i = ('a' as char) ^ ('b' as char)
+        ''').hasStrictSequence ([
+            'IXOR'
         ])
     }
 
+    // GROOVY-10657
+    void testPutAtValue() {
+        def sequence = compile '''
+            class C {
+                void putAt(String key, Object value) {
+                }
+            }
+
+            def obj = new C()
+            obj['key'] = 'xx'
+        '''
+    }
+
     void testPrimitiveOrAssign() {
         ['byte','int','short','long'].each { type ->
             assertScript """
-            $type[] b = new $type[1]
-            b[0] = 16
-            b[0] |= 2
-            assert b[0] == 18:"Failure for type $type"
+                $type[] array = new $type[1]
+                array[0] = 16
+                array[0] |= 2
+                assert array[0] == 18 : "Failure for type $type"
             """
-            }
+        }
     }
 
     void testPrimitiveAndAssign() {
         ['byte','int','short','long'].each { type ->
             assertScript """
-            $type[] b = new $type[1]
-            b[0] = 18
-            b[0] &= 2
-            assert b[0] == 2:"Failure for type $type"
+                $type[] array = new $type[1]
+                array[0] = 18
+                array[0] &= 2
+                assert array[0] == 2 : "Failure for type $type"
             """
-            }
+        }
     }
 }