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 5b18914b36 GROOVY-9611, GROOVY-11481: same-package reflective access 
to AIC's field
5b18914b36 is described below

commit 5b18914b3611ab124103e7a99af193cefd3883f1
Author: Eric Milles <[email protected]>
AuthorDate: Mon Sep 23 10:04:43 2024 -0500

    GROOVY-9611, GROOVY-11481: same-package reflective access to AIC's field
---
 src/test/groovy/bugs/Groovy9611.groovy | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/src/test/groovy/bugs/Groovy9611.groovy 
b/src/test/groovy/bugs/Groovy9611.groovy
index ba20083036..c017a48c5a 100644
--- a/src/test/groovy/bugs/Groovy9611.groovy
+++ b/src/test/groovy/bugs/Groovy9611.groovy
@@ -26,16 +26,20 @@ final class Groovy9611 {
     @Test
     void testAccessFieldWithinAICUsingReflection() {
         assertScript '''
-            import java.lang.reflect.Field
             class C {
-              int method() {
-                for (Field f : getClass().fields)
-                  if (f.name == 'i') return f.get(this)
-                return -1
-              }
+                @groovy.transform.CompileStatic
+                def m() {
+                    for (def f : getClass().getFields()) {
+                        if (f.name == 'i') return f.get(this)
+                    }
+                    return -1
+                }
             }
-            def c = new C() { public int i = 42 }
-            assert c.method() == 42
+
+            def c = new C() {
+                public final int i = 42
+            }
+            assert c.m() == 42
         '''
     }
 }

Reply via email to