You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2021/04/01 04:30:40 UTC

[groovy] 03/10: GROOVY-9993: Field and a property with the same name: clarification of boundary cases (test cases for properties with init values)

This is an automated email from the ASF dual-hosted git repository.

paulk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git

commit 34d12dfc980377f2cfbdd589298faad03469d87e
Author: Paul King <pa...@asert.com.au>
AuthorDate: Tue Mar 30 21:00:26 2021 +1000

    GROOVY-9993: Field and a property with the same name: clarification of boundary cases (test cases for properties with init values)
---
 .../MultipleDefinitionOfSameVariableTest.groovy    | 30 ++++++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/src/test/gls/scope/MultipleDefinitionOfSameVariableTest.groovy b/src/test/gls/scope/MultipleDefinitionOfSameVariableTest.groovy
index 82b7f5a..f0ebb42 100644
--- a/src/test/gls/scope/MultipleDefinitionOfSameVariableTest.groovy
+++ b/src/test/gls/scope/MultipleDefinitionOfSameVariableTest.groovy
@@ -163,4 +163,34 @@ class MultipleDefinitionOfSameVariableTest extends CompilableTestSupport {
         '''
     }
 
+    void testFieldAndPropertyWithInit() {
+        assertScript '''
+            class X {
+                def foo = 3
+                public foo
+                public bar
+                def bar = 4
+            }
+
+            def x = new X()
+            def result = [x.foo, x.bar]
+            assert result == [3, 4]
+        '''
+    }
+
+    void testPropertyAndFieldWithInit() {
+        assertScript '''
+            class Y {
+                def foo
+                public foo = 5
+                public bar = 6
+                def bar
+            }
+
+            def y = new Y()
+            result = [y.foo, y.bar]
+            assert result == [5, 6]
+        '''
+    }
+
 }
\ No newline at end of file