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/07/31 19:37:09 UTC

[groovy] branch GROOVY-9386 created (now 3a1acc5)

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

emilles pushed a change to branch GROOVY-9386
in repository https://gitbox.apache.org/repos/asf/groovy.git.


      at 3a1acc5  GROOVY-9386: traits: do not transform dynamic variable within closure

This branch includes the following new commits:

     new 3a1acc5  GROOVY-9386: traits: do not transform dynamic variable within closure

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[groovy] 01/01: GROOVY-9386: traits: do not transform dynamic variable within closure

Posted by em...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 3a1acc5a92ffbf3f4093bbc98d4405cf4fd668f0
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Fri Jul 31 14:36:55 2020 -0500

    GROOVY-9386: traits: do not transform dynamic variable within closure
---
 .../transform/trait/TraitReceiverTransformer.java  |  2 +-
 .../traitx/TraitASTTransformationTest.groovy       | 38 ++++++++++++++++++++++
 2 files changed, 39 insertions(+), 1 deletion(-)

diff --git a/src/main/java/org/codehaus/groovy/transform/trait/TraitReceiverTransformer.java b/src/main/java/org/codehaus/groovy/transform/trait/TraitReceiverTransformer.java
index 04b2cc0..ebb8947 100644
--- a/src/main/java/org/codehaus/groovy/transform/trait/TraitReceiverTransformer.java
+++ b/src/main/java/org/codehaus/groovy/transform/trait/TraitReceiverTransformer.java
@@ -149,7 +149,7 @@ class TraitReceiverTransformer extends ClassCodeExpressionTransformer {
                     propertyExpression.getProperty().setSourcePosition(exp);
                     return propertyExpression;
                 }
-            } else if (accessedVariable instanceof DynamicVariable) {
+            } else if (accessedVariable instanceof DynamicVariable && !inClosure) { // GROOVY-9386
                 PropertyExpression propertyExpression = propX(varX(weaved), vexp.getName());
                 propertyExpression.getProperty().setSourcePosition(exp);
                 return propertyExpression;
diff --git a/src/test/org/codehaus/groovy/transform/traitx/TraitASTTransformationTest.groovy b/src/test/org/codehaus/groovy/transform/traitx/TraitASTTransformationTest.groovy
index 11cf72c..81d6fd0 100644
--- a/src/test/org/codehaus/groovy/transform/traitx/TraitASTTransformationTest.groovy
+++ b/src/test/org/codehaus/groovy/transform/traitx/TraitASTTransformationTest.groovy
@@ -2849,6 +2849,44 @@ final class TraitASTTransformationTest {
         '''
     }
 
+    @Test // GROOVY-9386
+    void testTraitPropertyInitializedByTap() {
+        assertScript '''
+            class P {
+                int prop
+            }
+            trait T {
+                P pogo = new P().tap {
+                    prop = 42 // MissingPropertyException: No such property: prop for class: C
+                }
+            }
+            class C implements T {
+            }
+
+            def pogo = new C().pogo
+            assert pogo.prop == 42
+        '''
+    }
+
+    @Test // GROOVY-9386
+    void testTraitPropertyInitializedByWith() {
+        assertScript '''
+            class P {
+                int prop
+            }
+            trait T {
+                P pogo = new P().with {
+                    prop = 42 // MissingPropertyException: No such property: prop for class: C
+                    return it
+                }
+            }
+            class C implements T {
+            }
+            def pogo = new C().pogo
+            assert pogo.prop == 42
+        '''
+    }
+
     @Test // GROOVY-9660
     void testAsGenericsParam() {
         assertScript '''