You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by su...@apache.org on 2020/08/09 02:03:59 UTC

[groovy] branch danielsun/fix-3_0_0 updated (6537438 -> 8229e00)

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

sunlan pushed a change to branch danielsun/fix-3_0_0
in repository https://gitbox.apache.org/repos/asf/groovy.git.


 discard 6537438  minor refactor
     new 8229e00  GROOVY-9386: traits: do not transform dynamic variable within closure

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (6537438)
            \
             N -- N -- N   refs/heads/danielsun/fix-3_0_0 (8229e00)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

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.


Summary of changes:
 .../transform/trait/SuperCallTraitTransformer.java | 119 +++++++++++----------
 .../transform/trait/TraitReceiverTransformer.java  |   2 +-
 .../traitx/TraitASTTransformationTest.groovy       |  38 +++++++
 3 files changed, 104 insertions(+), 55 deletions(-)


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

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

sunlan pushed a commit to branch danielsun/fix-3_0_0
in repository https://gitbox.apache.org/repos/asf/groovy.git

commit 8229e0094b9a075ec084617454c8470178c1fcc0
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Sat Aug 8 08:39:26 2020 -0500

    GROOVY-9386: traits: do not transform dynamic variable within closure
    
    closes #1334
    
    (cherry picked from commit 03ef95584a356bb8c514f38c3b4d16eb4772a643)
---
 .../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 '''