File tree 3 files changed +43
-9
lines changed
main/java/org/codehaus/groovy/transform
test/groovy/org/codehaus/groovy/transform/traitx
3 files changed +43
-9
lines changed Original file line number Diff line number Diff line change @@ -40,6 +40,10 @@ class PropertyExpressionTransformer {
40
40
}
41
41
42
42
Expression transformPropertyExpression (final PropertyExpression pe ) {
43
+ if (pe .getNodeMetaData (StaticTypesMarker .DYNAMIC_RESOLUTION ) != null ) {
44
+ return pe .transformExpression (scTransformer ); // GROOVY-11641, etc.
45
+ }
46
+
43
47
MethodNode dmct = pe .getNodeMetaData (StaticTypesMarker .DIRECT_METHOD_CALL_TARGET );
44
48
// NOTE: BinaryExpressionTransformer handles the setter
45
49
if (dmct != null && dmct .getParameters ().length == 0 ) {
Original file line number Diff line number Diff line change @@ -122,7 +122,7 @@ public Expression transform(final Expression exp) {
122
122
propertyExpression .getProperty ().setSourcePosition (exp );
123
123
return propertyExpression ;
124
124
}
125
- } else if (accessedVariable instanceof DynamicVariable && !inClosure ) { // GROOVY-9386
125
+ } else if (accessedVariable instanceof DynamicVariable && !inClosure ) { // GROOVY-8049, GROOVY- 9386
126
126
PropertyExpression propertyExpression = propX (varX (weaved ), vexp .getName ());
127
127
propertyExpression .putNodeMetaData (DYNAMIC_RESOLUTION , Boolean .TRUE );
128
128
propertyExpression .getProperty ().setSourcePosition (exp );
Original file line number Diff line number Diff line change @@ -3749,43 +3749,73 @@ final class TraitASTTransformationTest {
3749
3749
}
3750
3750
3751
3751
// GROOVY-9386
3752
- @Test
3753
- void testTraitPropertyInitializedByTap () {
3754
- assertScript shell, '''
3752
+ @CompileModesTest
3753
+ void testTraitPropertyInitializedByTap (String mode ) {
3754
+ assertScript shell, """
3755
3755
class P {
3756
3756
int prop
3757
3757
}
3758
+ $mode
3758
3759
trait T {
3759
3760
P pogo = new P().tap {
3760
3761
prop = 42 // MissingPropertyException: No such property: prop for class: C
3761
3762
}
3762
3763
}
3764
+ $mode
3763
3765
class C implements T {
3764
3766
}
3765
3767
3766
3768
def pogo = new C().pogo
3767
3769
assert pogo.prop == 42
3768
- '''
3770
+ """
3769
3771
}
3770
3772
3771
3773
// GROOVY-9386
3772
- @Test
3773
- void testTraitPropertyInitializedByWith () {
3774
- assertScript shell, '''
3774
+ @CompileModesTest
3775
+ void testTraitPropertyInitializedByWith (String mode ) {
3776
+ assertScript shell, """
3775
3777
class P {
3776
3778
int prop
3777
3779
}
3780
+ $mode
3778
3781
trait T {
3779
3782
P pogo = new P().with {
3780
3783
prop = 42 // MissingPropertyException: No such property: prop for class: C
3781
3784
return it
3782
3785
}
3783
3786
}
3787
+ $mode
3784
3788
class C implements T {
3785
3789
}
3790
+
3786
3791
def pogo = new C().pogo
3787
3792
assert pogo.prop == 42
3788
- '''
3793
+ """
3794
+ }
3795
+
3796
+ // GROOVY-8049
3797
+ @CompileModesTest
3798
+ void testTraitPropertyAsReceiverForWith (String mode ) {
3799
+ assertScript shell, """
3800
+ interface I {
3801
+ String getJay()
3802
+ }
3803
+ $mode
3804
+ trait T {
3805
+ abstract I getEye()
3806
+ String m() {
3807
+ eye.with {
3808
+ jay.toUpperCase()
3809
+ }
3810
+ }
3811
+ }
3812
+ $mode
3813
+ class C implements T {
3814
+ I eye = { -> 'works' }
3815
+ }
3816
+
3817
+ assert new C().m() == 'WORKS'
3818
+ """
3789
3819
}
3790
3820
3791
3821
// GROOVY-8000
You can’t perform that action at this time.
0 commit comments