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/09/25 18:39:08 UTC
[groovy] branch GROOVY_3_0_X updated: GROOVY-9650, GROOVY-9655,
GROOVY-9665, GROOVY-9683, GROOVY-9695
This is an automated email from the ASF dual-hosted git repository.
emilles pushed a commit to branch GROOVY_3_0_X
in repository https://gitbox.apache.org/repos/asf/groovy.git
The following commit(s) were added to refs/heads/GROOVY_3_0_X by this push:
new 419ce2f GROOVY-9650, GROOVY-9655, GROOVY-9665, GROOVY-9683, GROOVY-9695
419ce2f is described below
commit 419ce2f91754f101d8e65977da4dc7e8e6b6265f
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Fri Sep 25 13:38:51 2020 -0500
GROOVY-9650, GROOVY-9655, GROOVY-9665, GROOVY-9683, GROOVY-9695
within closure requires static outer field resolution to fix regression
---
.../groovy/classgen/AsmClassGenerator.java | 9 ++-
.../stc/FieldsAndPropertiesSTCTest.groovy | 65 +++++++++++++++++++---
2 files changed, 60 insertions(+), 14 deletions(-)
diff --git a/src/main/java/org/codehaus/groovy/classgen/AsmClassGenerator.java b/src/main/java/org/codehaus/groovy/classgen/AsmClassGenerator.java
index 11cd892..2010e02 100644
--- a/src/main/java/org/codehaus/groovy/classgen/AsmClassGenerator.java
+++ b/src/main/java/org/codehaus/groovy/classgen/AsmClassGenerator.java
@@ -1084,11 +1084,10 @@ public class AsmClassGenerator extends ClassGenerator {
if (expression.isImplicitThis()) fieldNode = classNode.getDeclaredField(name);
} else {
fieldNode = classNode.getDeclaredField(name);
-
- if (fieldNode == null && !isValidFieldNodeForByteCodeAccess(classNode.getField(name), classNode)) {
- // GROOVY-9501, GROOVY-9569
- if (checkStaticOuterField(expression, name)) return;
- }
+ }
+ if (fieldNode == null && !isValidFieldNodeForByteCodeAccess(classNode.getField(name), classNode)) {
+ // GROOVY-9501, GROOVY-9569, GROOVY-9650, GROOVY-9655, GROOVY-9665, GROOVY-9683, GROOVY-9695
+ if (checkStaticOuterField(expression, name)) return;
}
} else {
fieldNode = classNode.getSuperClass().getDeclaredField(name);
diff --git a/src/test/groovy/transform/stc/FieldsAndPropertiesSTCTest.groovy b/src/test/groovy/transform/stc/FieldsAndPropertiesSTCTest.groovy
index ed0d16f..4b8ffb3 100644
--- a/src/test/groovy/transform/stc/FieldsAndPropertiesSTCTest.groovy
+++ b/src/test/groovy/transform/stc/FieldsAndPropertiesSTCTest.groovy
@@ -505,19 +505,66 @@ class FieldsAndPropertiesSTCTest extends StaticTypeCheckingTestCase {
void testPrivateFieldAccessInClosure() {
assertScript '''
- class A {
+ class C {
private int x
- void foo() {
- def cl = { x = 666 }
- cl()
- }
- void ensure() {
+ void test() {
+ def c = { -> x = 666 }
+ c()
assert x == 666
}
}
- def a = new A()
- a.foo()
- a.ensure()
+ new C().test()
+ '''
+ }
+
+ // GROOVY-9683
+ void testPrivateFieldAccessInClosure2() {
+ assertScript '''
+ class C {
+ private static X = 'xxx'
+ void test() {
+ [:].with {
+ assert X == 'xxx'
+ }
+ }
+ }
+ new C().test()
+ '''
+ }
+
+ void testPrivateFieldAccessInClosure3() {
+ assertScript '''
+ class C {
+ private static X = 'xxx'
+ void test() {
+ [:].withDefault { throw new MissingPropertyException(it.toString()) }.with {
+ assert X == 'xxx'
+ }
+ }
+ }
+ new C().test()
+ '''
+ }
+
+ // GROOVY-9695
+ void testPrivateFieldAccessInClosure4() {
+ assertScript '''
+ class C {
+ private static final X = 'xxx'
+ void test() {
+ Map m = [:]
+ def c = { ->
+ assert X == 'xxx'
+ m[X] = 123
+ }
+ c()
+ assert m == [xxx:123]
+ }
+ }
+ new C().test()
+ class D extends C {
+ }
+ new D().test()
'''
}