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/05/30 15:18:32 UTC
[groovy] 03/11: GROOVY-9499: add test case
This is an automated email from the ASF dual-hosted git repository.
sunlan pushed a commit to branch GROOVY_3_0_X
in repository https://gitbox.apache.org/repos/asf/groovy.git
commit 346a408a91679487d58157013219dcaa3b9e1414
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Thu May 28 10:08:44 2020 -0500
GROOVY-9499: add test case
(cherry picked from commit 2964e6f19f7d1271651cab46c55f6f508cdedcea)
---
src/test/gls/innerClass/InnerClassTest.groovy | 62 ++++++++++++++++++++++-----
1 file changed, 51 insertions(+), 11 deletions(-)
diff --git a/src/test/gls/innerClass/InnerClassTest.groovy b/src/test/gls/innerClass/InnerClassTest.groovy
index c07bcbc..9841344 100644
--- a/src/test/gls/innerClass/InnerClassTest.groovy
+++ b/src/test/gls/innerClass/InnerClassTest.groovy
@@ -37,6 +37,7 @@ final class InnerClassTest {
Timer timer = new Timer()
timer.schedule(new TimerTask() {
+ @Override
void run() {
called.countDown()
}
@@ -47,23 +48,36 @@ final class InnerClassTest {
}
@Test
- void testAICReferenceInClosure() {
+ void testAccessLocalVariableFromClosureInAIC() {
assertScript '''
- def y = [true]
+ def x = [true]
def o = new Object() {
- def foo() {
- def c = {
- assert y[0]
+ def m() {
+ def c = { ->
+ assert x[0]
+ }
+ c()
+ }
+ }
+ o.m()
+ '''
+
+ shouldFail '''
+ def x = [false]
+ def o = new Object() {
+ def m() {
+ def c = { ->
+ assert x[0]
+ }
+ c()
}
- c()
- }
}
- o.foo()
+ o.m()
'''
}
@Test
- void testExtendsObjectAndAccessAFinalVariableInScope() {
+ void testAccessFinalLocalVariableFromMethodInAIC() {
assertScript '''
final String objName = "My name is Guillaume"
@@ -73,8 +87,34 @@ final class InnerClassTest {
'''
}
+ @Test // GROOVY-9499
+ void testAccessStaticMethodFromAICInSuperCtorCall() {
+ assertScript '''
+ class One {
+ One(ref) {
+ HASH_CODE = ref.hashCode()
+ }
+ public static int HASH_CODE
+ }
+
+ class Two extends One {
+ Two() {
+ super(new Object() { // AIC before special ctor call completes
+ int hashCode() {
+ hash() // should be able to call static method safely
+ }
+ })
+ }
+ static int hash() { 42 }
+ }
+
+ def obj = new Two()
+ assert One.HASH_CODE == 42
+ '''
+ }
+
@Test
- void testExtendsObjectAndReferenceAMethodParameterWithinAGString() {
+ void testAccessMethodParameterFromGStringInAICMethod() {
assertScript '''
Object makeObj0(String name) {
new Object() {
@@ -87,7 +127,7 @@ final class InnerClassTest {
}
@Test
- void testExtendsObjectAndReferenceAGStringPropertyDependingOnAMethodParameter() {
+ void testAccessMethodParameterFromGStringInAICProperty() {
assertScript '''
Object makeObj1(String name) {
new Object() {