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 b862a36239 minor items
b862a36239 is described below

commit b862a36239c0d5ea59c0b6e1545a48ad17f1655e
Author: Eric Milles <[email protected]>
AuthorDate: Mon Dec 29 11:50:03 2025 -0600

    minor items
---
 src/test/groovy/bugs/Groovy5041.groovy             | 43 -------------------
 src/test/groovy/bugs/Groovy7951Bug.groovy          | 30 +++++++-------
 .../groovy/gls/innerClass/InnerClassTest.groovy    | 48 ++++++++++++++--------
 .../groovy/transform/stc/GenericsSTCTest.groovy    |  6 +--
 .../transform/stc/TypeInferenceSTCTest.groovy      |  8 ++--
 .../groovy/groovy/util/logging/Slf4jTest.groovy    |  6 +--
 .../codehaus/groovy/ast/GenericsTestCase.groovy    | 36 +++++++---------
 7 files changed, 71 insertions(+), 106 deletions(-)

diff --git a/src/test/groovy/bugs/Groovy5041.groovy 
b/src/test/groovy/bugs/Groovy5041.groovy
deleted file mode 100644
index a495a39203..0000000000
--- a/src/test/groovy/bugs/Groovy5041.groovy
+++ /dev/null
@@ -1,43 +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 Groovy5041 {
-    @Test
-    void testAICParameter() {
-        assertScript '''
-            abstract class A {
-                A(x) {}
-                abstract call()
-            }
-
-            def x = 1
-            def a = new A(x) {
-                def call() { x }
-            }
-            assert a.call() == 1
-            x = 2
-            assert a.call() == 2
-        '''
-    }
-}
diff --git a/src/test/groovy/bugs/Groovy7951Bug.groovy 
b/src/test/groovy/bugs/Groovy7951Bug.groovy
index 676f644d32..4a943249ba 100644
--- a/src/test/groovy/bugs/Groovy7951Bug.groovy
+++ b/src/test/groovy/bugs/Groovy7951Bug.groovy
@@ -18,48 +18,51 @@
  */
 package bugs
 
-import groovy.test.GroovyTestCase
 import org.codehaus.groovy.ast.ClassCodeExpressionTransformer
 import org.codehaus.groovy.ast.ClassCodeVisitorSupport
 import org.codehaus.groovy.ast.ClassNode
 import org.codehaus.groovy.ast.expr.MethodCallExpression
+import org.codehaus.groovy.classgen.GeneratorContext
 import org.codehaus.groovy.control.CompilerConfiguration
 import org.codehaus.groovy.control.SourceUnit
 import org.codehaus.groovy.control.customizers.CompilationCustomizer
-import org.codehaus.groovy.classgen.GeneratorContext
+import org.junit.jupiter.api.Test
 
 import static org.codehaus.groovy.control.CompilePhase.CANONICALIZATION
 import static org.codehaus.groovy.control.CompilePhase.INSTRUCTION_SELECTION
 
-class Groovy7951Bug extends GroovyTestCase {
+final class Groovy7951Bug {
 
+    @Test
     void testTransformMethodCallExpressionPassesGenericTypes() {
-
         def config = new CompilerConfiguration()
 
         // Just visiting the transform method on each expression is enough to 
verify
         // that the checker is able to see the generic types in the later 
phase.
         def transformer = new CompilationCustomizer(CANONICALIZATION) {
-            @Override void call(SourceUnit src, GeneratorContext ctxt, 
ClassNode cn) {
+            @Override
+            void call(SourceUnit su, GeneratorContext gc, ClassNode cn) {
                 new ClassCodeExpressionTransformer() {
-                    @Override SourceUnit getSourceUnit() { src }
+                    @Override SourceUnit getSourceUnit() { su }
                 }.visitClass(cn)
             }
         }
 
-        boolean assertWasChecked
         def checker = new CompilationCustomizer(INSTRUCTION_SELECTION) {
-            void call(SourceUnit src, GeneratorContext ctxt, ClassNode cn) {
+            boolean assertWasChecked
+            @Override
+            void call(SourceUnit su, GeneratorContext gc, ClassNode cn) {
                 new ClassCodeVisitorSupport() {
-                    @Override void 
visitMethodCallExpression(MethodCallExpression mce) {
-                        if (mce.objectExpression.text == 
'java.util.Collections' &&
-                                mce.method.text == 'emptyList') {
+                    @Override
+                    SourceUnit getSourceUnit() { su }
+                    @Override
+                    void visitMethodCallExpression(MethodCallExpression mce) {
+                        if (mce.objectExpression.text == 
'java.util.Collections' && mce.method.text == 'emptyList') {
                             assert mce.genericsTypes != null && 
mce.genericsTypes*.name == ['Date']
                             assertWasChecked = true
                         }
                         super.visitMethodCallExpression(mce)
                     }
-                    @Override SourceUnit getSourceUnit() { src }
                 }.visitClass(cn)
             }
         }
@@ -70,7 +73,6 @@ class Groovy7951Bug extends GroovyTestCase {
             Collections.<Date>emptyList()
         '''
 
-        assert assertWasChecked
+        assert checker.assertWasChecked
     }
-
 }
diff --git a/src/test/groovy/gls/innerClass/InnerClassTest.groovy 
b/src/test/groovy/gls/innerClass/InnerClassTest.groovy
index a4dfd08bc7..89ceaedc2d 100644
--- a/src/test/groovy/gls/innerClass/InnerClassTest.groovy
+++ b/src/test/groovy/gls/innerClass/InnerClassTest.groovy
@@ -141,6 +141,35 @@ final class InnerClassTest {
         '''
     }
 
+    @Test
+    void testAccessLocalVariableInAIC() {
+        assertScript '''
+            final String objName = 'My name is Guillaume'
+
+            assert new Object() {
+                String toString() { objName }
+            }.toString() == objName
+        '''
+    }
+
+    // GROOVY-5041
+    @Test
+    void testAccessLocalVariableInAIC2() {
+        assertScript '''
+            abstract class A {
+                abstract call()
+            }
+
+            def x = 1
+            def a = new A() {
+                def call() { x }
+            }
+            assert a.call() == 1
+            x = 2
+            assert a.call() == 2
+        '''
+    }
+
     // GROOVY-8448
     @Test
     void testAccessLocalVariableVsGetterInAIC() {
@@ -186,17 +215,6 @@ final class InnerClassTest {
         '''
     }
 
-    @Test
-    void testAccessFinalLocalVariableFromMethodInAIC() {
-        assertScript '''
-            final String objName = "My name is Guillaume"
-
-            assert new Object() {
-                String toString() { objName }
-            }.toString() == objName
-        '''
-    }
-
     // GROOVY-9825
     @Test
     void testAccessSuperInterfaceConstantWithInnerClass() {
@@ -1558,17 +1576,13 @@ final class InnerClassTest {
     void testReferencedVariableInAIC3() {
         assertScript '''
             abstract class A {
-                A() {
-                    m()
-                }
-                abstract void m();
+                abstract void m()
             }
             void test() {
                 def v = false
                 def a = new A() {
-                    // run by super ctor
                     @Override void m() {
-                        assert v != null
+                        assert v == true
                     }
                 }
                 v = true
diff --git a/src/test/groovy/groovy/transform/stc/GenericsSTCTest.groovy 
b/src/test/groovy/groovy/transform/stc/GenericsSTCTest.groovy
index 7d566a03a0..f2a5246973 100644
--- a/src/test/groovy/groovy/transform/stc/GenericsSTCTest.groovy
+++ b/src/test/groovy/groovy/transform/stc/GenericsSTCTest.groovy
@@ -5016,14 +5016,14 @@ class GenericsSTCTest extends 
StaticTypeCheckingTestCase {
                 function.apply('')
             }
 
-            String result = null
+            def result = new String[1]
             transform(new Function<String, String>() {
                 String apply(String input) {
-                    result = "ok"
+                    result[0] = 'ok'
                 }
             })
 
-            assert result == 'ok'
+            assert result[0] == 'ok'
         '''
     }
 
diff --git a/src/test/groovy/groovy/transform/stc/TypeInferenceSTCTest.groovy 
b/src/test/groovy/groovy/transform/stc/TypeInferenceSTCTest.groovy
index 1444495ed3..c94d1d55d3 100644
--- a/src/test/groovy/groovy/transform/stc/TypeInferenceSTCTest.groovy
+++ b/src/test/groovy/groovy/transform/stc/TypeInferenceSTCTest.groovy
@@ -1027,16 +1027,15 @@ class TypeInferenceSTCTest extends 
StaticTypeCheckingTestCase {
             }
         ''',
         'Cannot find matching method java.lang.Integer#toUpperCase()'
-   }
+    }
 
     void testDeclarationTypeInference() {
-        MethodNode method
+        Reference<MethodNode> method = []
         config.addCompilationCustomizers(new 
CompilationCustomizer(CompilePhase.CLASS_GENERATION) {
             @Override
             void call(SourceUnit source, GeneratorContext context, ClassNode 
classNode) {
-                method = classNode.methods.find { it.name == 'method' }
+                method.set(classNode.methods.find { it.name == 'method' })
             }
-
         })
         assertScript '''
             void method() {
@@ -1045,6 +1044,7 @@ class TypeInferenceSTCTest extends 
StaticTypeCheckingTestCase {
                 o = 'String'
             }
         '''
+
         def inft = 
method.code.statements[0].expression.leftExpression.getNodeMetaData(StaticTypesMarker.DECLARATION_INFERRED_TYPE)
         assert inft instanceof WideningCategories.LowestUpperBoundClassNode
         [Comparable, Serializable].each {
diff --git a/src/test/groovy/groovy/util/logging/Slf4jTest.groovy 
b/src/test/groovy/groovy/util/logging/Slf4jTest.groovy
index d5199334ca..8bb3baa126 100644
--- a/src/test/groovy/groovy/util/logging/Slf4jTest.groovy
+++ b/src/test/groovy/groovy/util/logging/Slf4jTest.groovy
@@ -335,13 +335,13 @@ final class Slf4jTest {
                 static myMethod() {
                     String message = 'hello'
                     String audience = 'world'
-                    String result
+                    def value = new String[1]
                     new Runnable() {
                         void run() {
-                            result = "$message $audience"
+                            value[0] = "$message $audience"
                         }
                     }.run()
-                    result
+                    value[0]
                 }
             }
             assert MyClass.myMethod() == 'hello world'
diff --git a/src/test/groovy/org/codehaus/groovy/ast/GenericsTestCase.groovy 
b/src/test/groovy/org/codehaus/groovy/ast/GenericsTestCase.groovy
index 349172029b..b71e16e8b3 100644
--- a/src/test/groovy/org/codehaus/groovy/ast/GenericsTestCase.groovy
+++ b/src/test/groovy/org/codehaus/groovy/ast/GenericsTestCase.groovy
@@ -19,19 +19,20 @@
 package org.codehaus.groovy.ast
 
 import groovy.test.GroovyTestCase
+import groovy.transform.TupleConstructor
+import org.codehaus.groovy.ast.expr.VariableExpression
 import org.codehaus.groovy.classgen.GeneratorContext
-import org.codehaus.groovy.control.SourceUnit
 import org.codehaus.groovy.control.CompilePhase
-import org.codehaus.groovy.control.customizers.CompilationCustomizer
 import org.codehaus.groovy.control.CompilerConfiguration
-import org.codehaus.groovy.ast.expr.VariableExpression
+import org.codehaus.groovy.control.SourceUnit
+import org.codehaus.groovy.control.customizers.CompilationCustomizer
 
 /**
  * Adds several utility methods which are used in tests on generics.
  */
 abstract class GenericsTestCase extends GroovyTestCase {
 
-    def extractTypesFromCode(String string) {
+    protected Map<String, Object> extractTypesFromCode(String string) {
         def result = [generics:[], type:null]
         CompilerConfiguration config = new CompilerConfiguration()
         config.addCompilationCustomizers(new 
CompilationCustomizer(CompilePhase.CANONICALIZATION) {
@@ -39,9 +40,9 @@ abstract class GenericsTestCase extends GroovyTestCase {
             void call(SourceUnit source, GeneratorContext context, ClassNode 
classNode) {
                 def visitor = new GenericsVisitorSupport(source)
                 visitor.visitClass(classNode)
-                result = visitor.result
+                result.clear()
+                result.putAll(visitor.result)
             }
-
         })
 
         new GroovyShell(config).evaluate(string)
@@ -49,37 +50,28 @@ abstract class GenericsTestCase extends GroovyTestCase {
         result
     }
 
+    @TupleConstructor(defaults=false)
     private static class GenericsVisitorSupport extends 
ClassCodeVisitorSupport {
 
-        private final SourceUnit sourceUnit
-        private final Map result = [:]
-
-        private GenericsVisitorSupport(SourceUnit unit) {
-            sourceUnit = unit
-        }
-
-        @Override
-        protected SourceUnit getSourceUnit() {
-            return sourceUnit
-        }
+        final SourceUnit sourceUnit
+        private final Map<String, Object> result = [:]
 
         @Override
         void visitVariableExpression(VariableExpression expression) {
             super.visitVariableExpression(expression)
-            if (expression.name=='type') {
-                result.generics = expression.type.genericsTypes
+            if (expression.name == 'type') {
                 result.type = expression.type
+                result.generics = expression.type.genericsTypes
             }
         }
 
         @Override
         void visitMethod(MethodNode node) {
             super.visitMethod(node)
-            if (node.name=='type') {
-                result.generics = node.genericsTypes
+            if (node.name == 'type') {
                 result.type = node.returnType
+                result.generics = node.genericsTypes
             }
         }
-
     }
 }

Reply via email to