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 2022/01/31 21:08:04 UTC

[groovy] 06/06: GROOVY-9973: add test case

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

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

commit 2f82d2fd63fe073b5fbf4f601970ad6d37fc476d
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Tue Mar 9 09:31:14 2021 -0600

    GROOVY-9973: add test case
---
 .../stc/FieldsAndPropertiesSTCTest.groovy          | 34 ++++++++++++++++------
 1 file changed, 25 insertions(+), 9 deletions(-)

diff --git a/src/test/groovy/transform/stc/FieldsAndPropertiesSTCTest.groovy b/src/test/groovy/transform/stc/FieldsAndPropertiesSTCTest.groovy
index 3a77d47e..0e55f07 100644
--- a/src/test/groovy/transform/stc/FieldsAndPropertiesSTCTest.groovy
+++ b/src/test/groovy/transform/stc/FieldsAndPropertiesSTCTest.groovy
@@ -237,21 +237,37 @@ class FieldsAndPropertiesSTCTest extends StaticTypeCheckingTestCase {
         '''
     }
 
-    void testMethodUsageForProperty() {
+    void testDateProperties() {
         assertScript '''
-            class Foo {
-                String name
+            Date d = new Date()
+            def time = d.time
+            d.time = 0
+        '''
+    }
+
+    void testGetterForProperty1() {
+        assertScript '''
+            class C {
+                String p
             }
-            def name = new Foo().getName()
-            name?.toUpperCase()
+            def x = new C().getP()
+            x = x?.toUpperCase()
         '''
     }
 
-    void testDateProperties() {
+    // GROOVY-9973
+    void testGetterForProperty2() {
         assertScript '''
-            Date d = new Date()
-            def time = d.time
-            d.time = 0
+            class C {
+                private int f
+                int getP() { f }
+                Integer m() { 123456 - p }
+                Integer m(int i) { i - p }
+            }
+
+            def c = new C()
+            assert c.m() == 123456 // BUG! exception in phase 'class generation' ...
+            assert c.m(123) == 123 // ClassCastException: class org.codehaus.groovy.ast.Parameter cannot be cast to ...
         '''
     }