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 2026/03/11 16:12:30 UTC
(groovy) branch GROOVY_5_0_X updated: GROOVY-11872: SC: propagate `STATIC_COMPILE_NODE` metadata in `Verifier`
This is an automated email from the ASF dual-hosted git repository.
emilles pushed a commit to branch GROOVY_5_0_X
in repository https://gitbox.apache.org/repos/asf/groovy.git
The following commit(s) were added to refs/heads/GROOVY_5_0_X by this push:
new c136326a10 GROOVY-11872: SC: propagate `STATIC_COMPILE_NODE` metadata in `Verifier`
c136326a10 is described below
commit c136326a104f8c0488ecca94521707b21d702637
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Wed Mar 11 11:07:28 2026 -0500
GROOVY-11872: SC: propagate `STATIC_COMPILE_NODE` metadata in `Verifier`
5_0_X backport
---
.../org/codehaus/groovy/classgen/Verifier.java | 2 +
.../sc/CombinedIndyAndStaticCompilationTest.groovy | 144 +++++++++++++--------
2 files changed, 93 insertions(+), 53 deletions(-)
diff --git a/src/main/java/org/codehaus/groovy/classgen/Verifier.java b/src/main/java/org/codehaus/groovy/classgen/Verifier.java
index a2b12b5905..7ce43d5b48 100644
--- a/src/main/java/org/codehaus/groovy/classgen/Verifier.java
+++ b/src/main/java/org/codehaus/groovy/classgen/Verifier.java
@@ -124,6 +124,7 @@ import static org.codehaus.groovy.ast.tools.GenericsUtils.correctToGenericsSpec;
import static org.codehaus.groovy.ast.tools.GenericsUtils.createGenericsSpec;
import static org.codehaus.groovy.ast.tools.GenericsUtils.parameterizeType;
import static org.codehaus.groovy.ast.tools.PropertyNodeUtils.adjustPropertyModifiersForMethod;
+import static org.codehaus.groovy.transform.sc.StaticCompilationMetadataKeys.STATIC_COMPILE_NODE;
/**
* Verifies the AST node and adds any default AST code before bytecode generation occurs.
@@ -1022,6 +1023,7 @@ public class Verifier implements GroovyClassVisitor, Opcodes {
addPropertyMethod(newMethod);
newMethod.putNodeMetaData(DEFAULT_PARAMETER_GENERATED, Boolean.TRUE);
+ newMethod.putNodeMetaData(STATIC_COMPILE_NODE, method.getNodeMetaData(STATIC_COMPILE_NODE));
});
}
diff --git a/src/test/groovy/org/codehaus/groovy/classgen/asm/sc/CombinedIndyAndStaticCompilationTest.groovy b/src/test/groovy/org/codehaus/groovy/classgen/asm/sc/CombinedIndyAndStaticCompilationTest.groovy
index def803299d..6b0653440d 100644
--- a/src/test/groovy/org/codehaus/groovy/classgen/asm/sc/CombinedIndyAndStaticCompilationTest.groovy
+++ b/src/test/groovy/org/codehaus/groovy/classgen/asm/sc/CombinedIndyAndStaticCompilationTest.groovy
@@ -20,73 +20,111 @@ package org.codehaus.groovy.classgen.asm.sc
import org.codehaus.groovy.classgen.asm.AbstractBytecodeTestCase
import org.junit.jupiter.api.Test
+import org.junit.jupiter.params.ParameterizedTest
+import org.junit.jupiter.params.provider.ValueSource
import static org.codehaus.groovy.control.CompilerConfiguration.DEFAULT as config
import static org.junit.jupiter.api.Assumptions.assumeTrue
/**
- * Tests for combined static compilation and indy code
+ * Tests for combined static compilation and indy code.
*/
final class CombinedIndyAndStaticCompilationTest extends AbstractBytecodeTestCase {
+ @ParameterizedTest
+ @ValueSource(strings=['byte','short','int','long','float','double','boolean','char'])
+ void testArrayRead(String type) {
+ assumeTrue config.indyEnabled
+
+ def bytecode = compile method:'test', """
+ @groovy.transform.CompileStatic
+ void test() {
+ ${type}[] array = new ${type}[10]
+ ${type} x = array[0]
+ }
+ """
+ int offset = bytecode.indexOf('--BEGIN--') + 4
+ assert bytecode.indexOf('INVOKEDYNAMIC', offset) > offset
+ assert bytecode.indexOf('INVOKEDYNAMIC', offset) < bytecode.indexOf('--END--')
+ }
+
+ @ParameterizedTest
+ @ValueSource(strings=['byte','short','int','long','float','double','boolean','char'])
+ void testArrayWrite(String type) {
+ assumeTrue config.indyEnabled
+
+ def bytecode = compile method:'test', """
+ @groovy.transform.CompileStatic
+ void test() {
+ ${type}[] array = new ${type}[10]
+ array[0] = 1
+ }
+ """
+ int offset = bytecode.indexOf('--BEGIN--') + 4
+ assert bytecode.indexOf('INVOKEDYNAMIC', offset) > offset
+ assert bytecode.indexOf('INVOKEDYNAMIC', offset) < bytecode.indexOf('--END--')
+ }
+
+ @ParameterizedTest
+ @ValueSource(strings=['byte','short','int','long','float','double','char'])
+ void testNegativeIndex(String type) {
+ assertScript """
+ @groovy.transform.CompileStatic
+ void test() {
+ ${type}[] array = [0,1,2]
+ assert array[0] == 0
+ assert array[1] == 1
+ assert array[2] == 2
+ assert array[-1] == 2
+ assert array[-2] == 1
+ array[0] = 9
+ assert array[0] == 9
+ array[-1] = 8
+ assert array[2] == 8
+ }
+ test()
+ """
+ }
+
@Test
- void testArrayAccess() {
- assumeTrue(config.indyEnabled)
- ["byte", "short", "int", "long", "float", "double", "boolean", "char"].each { type->
- //array get
- compile ("""
- @groovy.transform.CompileStatic
- def foo() {
- ${type}[] array = new ${type}[10]
- $type x = array[0]
- }
- """).hasSequence(["INVOKEDYNAMIC"])
- //array set
- compile ("""
- @groovy.transform.CompileStatic
- def foo() {
- ${type}[] array = new ${type}[10]
- array[0] = 1
- }
- """).hasSequence(["INVOKEDYNAMIC"])
- }
+ void testNegativeIndexPrimitiveBoolean() {
+ assertScript '''
+ @groovy.transform.CompileStatic
+ void test() {
+ boolean[] array = [false, false, true]
+ assert array[0] == false
+ assert array[1] == false
+ assert array[2] == true
+ assert array[-1] == true
+ assert array[-2] == false
+ array[0] = true
+ assert array[0] == true
+ array[-1] = false
+ assert array[2] == false
+ }
+ test()
+ '''
}
+ // GROOVY-11872
@Test
- void testNegativeAccess() {
- ["byte", "short", "int", "long", "float", "double", "char"].each { type ->
- assertScript """
+ void testCompileStaticAndDefaultParameter() {
+ def bytecode = compile '''
+ class Foo {
@groovy.transform.CompileStatic
- def foo() {
- ${type}[] array = [0,1,2]
- assert array[0] == 0
- assert array[1] == 1
- assert array[2] == 2
- assert array[-1] == 2
- assert array[-2] == 1
- array[0] = 9
- assert array[0] == 9
- array[-1] = 8
- assert array[2] == 8
+ void bar(List list = baz()) {
+ for (item in list) {
+ println item
+ }
}
- foo()
- """
- }
- assertScript """
- @groovy.transform.CompileStatic
- def foo() {
- boolean[] array = [false, false, true]
- assert array[0] == false
- assert array[1] == false
- assert array[2] == true
- assert array[-1] == true
- assert array[-2] == false
- array[0] = true
- assert array[0] == true
- array[-1] = false
- assert array[2] == false
+ List baz() {
+ ['fizz','buzz']
}
- foo()
- """
+ }
+ '''
+ int offset = bytecode.indexOf('public bar()')
+ assert bytecode.indexOf('INVOKEDYNAMIC', offset) < 0
+ assert bytecode.indexOf('INVOKEVIRTUAL', offset) > offset
+ assert bytecode.indexOf('INVOKEVIRTUAL', offset) < bytecode.indexOf('RETURN', offset)
}
}