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 2020/05/28 15:08:51 UTC

[groovy] branch master updated: GROOVY-9499: add test case

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 2964e6f  GROOVY-9499: add test case
2964e6f is described below

commit 2964e6f19f7d1271651cab46c55f6f508cdedcea
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Thu May 28 10:08:44 2020 -0500

    GROOVY-9499: add test case
---
 src/test/gls/innerClass/InnerClassTest.groovy | 62 ++++++++++++++++++++++-----
 1 file changed, 51 insertions(+), 11 deletions(-)

diff --git a/src/test/gls/innerClass/InnerClassTest.groovy b/src/test/gls/innerClass/InnerClassTest.groovy
index 44b5ad2..a9ba77a 100644
--- a/src/test/gls/innerClass/InnerClassTest.groovy
+++ b/src/test/gls/innerClass/InnerClassTest.groovy
@@ -39,6 +39,7 @@ final class InnerClassTest {
 
             Timer timer = new Timer()
             timer.schedule(new TimerTask() {
+                @Override
                 void run() {
                     called.countDown()
                 }
@@ -49,23 +50,36 @@ final class InnerClassTest {
     }
 
     @Test
-    void testAICReferenceInClosure() {
+    void testAccessLocalVariableFromClosureInAIC() {
         assertScript '''
-            def y = [true]
+            def x = [true]
             def o = new Object() {
-              def foo() {
-                def c = {
-                  assert y[0]
+                def m() {
+                    def c = { ->
+                        assert x[0]
+                    }
+                    c()
+                }
+            }
+            o.m()
+        '''
+
+        shouldFail '''
+            def x = [false]
+            def o = new Object() {
+                def m() {
+                    def c = { ->
+                        assert x[0]
+                    }
+                    c()
                 }
-                c()
-              }
             }
-            o.foo()
+            o.m()
         '''
     }
 
     @Test
-    void testExtendsObjectAndAccessAFinalVariableInScope() {
+    void testAccessFinalLocalVariableFromMethodInAIC() {
         assertScript '''
             final String objName = "My name is Guillaume"
 
@@ -75,8 +89,34 @@ final class InnerClassTest {
         '''
     }
 
+    @Test // GROOVY-9499
+    void testAccessStaticMethodFromAICInSuperCtorCall() {
+        assertScript '''
+            class One {
+                One(ref) {
+                    HASH_CODE = ref.hashCode()
+                }
+                public static int HASH_CODE
+            }
+
+            class Two extends One {
+              Two() {
+                super(new Object() { // AIC before special ctor call completes
+                  int hashCode() {
+                    hash() // should be able to call static method safely
+                  }
+                })
+              }
+              static int hash() { 42 }
+            }
+
+            def obj = new Two()
+            assert One.HASH_CODE == 42
+        '''
+    }
+
     @Test
-    void testExtendsObjectAndReferenceAMethodParameterWithinAGString() {
+    void testAccessMethodParameterFromGStringInAICMethod() {
         assertScript '''
             Object makeObj0(String name) {
                 new Object() {
@@ -89,7 +129,7 @@ final class InnerClassTest {
     }
 
     @Test
-    void testExtendsObjectAndReferenceAGStringPropertyDependingOnAMethodParameter() {
+    void testAccessMethodParameterFromGStringInAICProperty() {
         assertScript '''
             Object makeObj1(String name) {
                  new Object() {