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/09/25 20:15:41 UTC

[groovy] branch master updated: GROOVY-9683, GROOVY-9695: add test cases

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 a06f495  GROOVY-9683, GROOVY-9695: add test cases
a06f495 is described below

commit a06f495146ce1146e4cbd239738165e13600070a
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Fri Sep 25 15:15:26 2020 -0500

    GROOVY-9683, GROOVY-9695: add test cases
---
 .../stc/FieldsAndPropertiesSTCTest.groovy          | 29 ++++++++++++-----
 .../sc/FieldsAndPropertiesStaticCompileTest.groovy | 38 ++++++++++++++++++++++
 2 files changed, 58 insertions(+), 9 deletions(-)

diff --git a/src/test/groovy/transform/stc/FieldsAndPropertiesSTCTest.groovy b/src/test/groovy/transform/stc/FieldsAndPropertiesSTCTest.groovy
index ed0d16f..c7d236e 100644
--- a/src/test/groovy/transform/stc/FieldsAndPropertiesSTCTest.groovy
+++ b/src/test/groovy/transform/stc/FieldsAndPropertiesSTCTest.groovy
@@ -503,21 +503,32 @@ class FieldsAndPropertiesSTCTest extends StaticTypeCheckingTestCase {
         ''', 'No such property: p for class: Outer$Inner'
     }
 
-    void testPrivateFieldAccessInClosure() {
+    void testPrivateFieldAccessInClosure1() {
         assertScript '''
             class A {
                 private int x
-                void foo() {
-                    def cl = { x = 666 }
-                    cl()
-                }
-                void ensure() {
+                void test() {
+                    def c = { -> x = 666 }
+                    c()
                     assert x == 666
                 }
             }
-            def a = new A()
-            a.foo()
-            a.ensure()
+            new A().test()
+        '''
+    }
+
+    // GROOVY-9683
+    void testPrivateFieldAccessInClosure2() {
+        assertScript '''
+            class A {
+                private static X = 'xxx'
+                void test() {
+                    [:].withDefault { throw new MissingPropertyException(it.toString()) }.with {
+                        assert X == 'xxx'
+                    }
+                }
+            }
+            new A().test()
         '''
     }
 
diff --git a/src/test/org/codehaus/groovy/classgen/asm/sc/FieldsAndPropertiesStaticCompileTest.groovy b/src/test/org/codehaus/groovy/classgen/asm/sc/FieldsAndPropertiesStaticCompileTest.groovy
index 81c5c83..34315e2 100644
--- a/src/test/org/codehaus/groovy/classgen/asm/sc/FieldsAndPropertiesStaticCompileTest.groovy
+++ b/src/test/org/codehaus/groovy/classgen/asm/sc/FieldsAndPropertiesStaticCompileTest.groovy
@@ -838,4 +838,42 @@ final class FieldsAndPropertiesStaticCompileTest extends FieldsAndPropertiesSTCT
             assert new A(['foo1', 'foo2']).fooNames.size() == 2
         '''
     }
+
+    // GROOVY-9683
+    void testPrivateFieldAccessInClosure3() {
+        assertScript '''
+            class A {
+                private static X = 'xxx'
+                void test() {
+                    [:].with {
+                        assert X == 'xxx'
+                    }
+                }
+            }
+            new A().test()
+        '''
+    }
+
+    // GROOVY-9695
+    void testPrivateFieldAccessInClosure4() {
+        assertScript '''
+            class A {
+                private static final X = 'xxx'
+                void test() {
+                    Map m = [:]
+                    def c = { ->
+                        assert X == 'xxx'
+                        m[X] = 123
+                    }
+                    c()
+                    assert m == [xxx:123]
+                }
+            }
+            new A().test()
+
+            class B extends A {
+            }
+            new B().test()
+        '''
+    }
 }