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
commit 7c0c0d0bfcda3f59febbf268f9ccc132b697b074 Author: Eric Milles <[email protected]> AuthorDate: Tue Dec 14 14:58:14 2021 -0600 GROOVY-10414: STC: set non-static outer class property via setter method Conflicts: src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java --- src/test/gls/innerClass/InnerClassTest.groovy | 13 +++++++++ .../stc/FieldsAndPropertiesSTCTest.groovy | 28 ++++++++++++++---- .../groovy/transform/stc/STCAssignmentTest.groovy | 34 +++++++++++++--------- 3 files changed, 56 insertions(+), 19 deletions(-) diff --git a/src/test/gls/innerClass/InnerClassTest.groovy b/src/test/gls/innerClass/InnerClassTest.groovy index e407f95..618d9d4 100644 --- a/src/test/gls/innerClass/InnerClassTest.groovy +++ b/src/test/gls/innerClass/InnerClassTest.groovy @@ -670,6 +670,19 @@ final class InnerClassTest { assert err =~ /Apparent variable 'count' was found in a static scope but doesn't refer to a local variable, static field or class./ } + @Test // GROOVY-8050 + void testUsageOfOuterField13() { + assertScript ''' + class Outer { + class Inner { + } + def p = 1 + } + def i = new Outer.Inner(new Outer()) + assert i.p == 1 + ''' + } + @Test void testUsageOfOuterSuperField() { assertScript ''' diff --git a/src/test/groovy/transform/stc/FieldsAndPropertiesSTCTest.groovy b/src/test/groovy/transform/stc/FieldsAndPropertiesSTCTest.groovy index 7e9ae33..e2c57ad 100644 --- a/src/test/groovy/transform/stc/FieldsAndPropertiesSTCTest.groovy +++ b/src/test/groovy/transform/stc/FieldsAndPropertiesSTCTest.groovy @@ -564,8 +564,26 @@ class FieldsAndPropertiesSTCTest extends StaticTypeCheckingTestCase { ''' } - // GROOVY-8050 + // GROOVY-10414 void testOuterPropertyAccess3() { + assertScript ''' + class Outer { + class Inner { + def m() { + setP(2) + getP() + } + } + def p = 1 + } + def i = new Outer.Inner(new Outer()) + def x = i.m() + assert x == 2 + ''' + } + + // GROOVY-8050 + void testOuterPropertyAccess4() { shouldFailWithMessages ''' class Outer { class Inner { @@ -579,7 +597,7 @@ class FieldsAndPropertiesSTCTest extends StaticTypeCheckingTestCase { } // GROOVY-8050 - void testOuterPropertyAccess4() { + void testOuterPropertyAccess5() { shouldFailWithMessages ''' class Outer { class Inner { @@ -593,7 +611,7 @@ class FieldsAndPropertiesSTCTest extends StaticTypeCheckingTestCase { } // GROOVY-9598 - void testOuterPropertyAccess5() { + void testOuterPropertyAccess6() { shouldFailWithMessages ''' class Outer { static class Inner { @@ -608,7 +626,7 @@ class FieldsAndPropertiesSTCTest extends StaticTypeCheckingTestCase { ''', 'The variable [p] is undeclared.' } - void testOuterPropertyAccess6() { + void testOuterPropertyAccess7() { shouldFailWithMessages ''' class Outer { static class Inner { @@ -624,7 +642,7 @@ class FieldsAndPropertiesSTCTest extends StaticTypeCheckingTestCase { } // GROOVY-7024 - void testOuterPropertyAccess7() { + void testOuterPropertyAccess8() { assertScript ''' class Outer { static Map props = [bar: 10, baz: 20] diff --git a/src/test/groovy/transform/stc/STCAssignmentTest.groovy b/src/test/groovy/transform/stc/STCAssignmentTest.groovy index 1c6752a..462334c 100644 --- a/src/test/groovy/transform/stc/STCAssignmentTest.groovy +++ b/src/test/groovy/transform/stc/STCAssignmentTest.groovy @@ -573,13 +573,13 @@ class STCAssignmentTest extends StaticTypeCheckingTestCase { ['I', 'def', 'var', 'Object'].each { assertScript """ interface I { - def foo() + def m() } class A implements I { - def foo() { 'A' } + def m() { 'A' } } class B implements I { - def foo() { 'B' } + def m() { 'B' } } $it x @@ -590,34 +590,40 @@ class STCAssignmentTest extends StaticTypeCheckingTestCase { } else if (z) { x = new B() } - assert x.foo() == 'B' + assert x.m() == 'B' """ } } - void testForLoopWithNewAssignment() { + void testForLoopWithAssignment() { shouldFailWithMessages ''' def x = '123' - for (int i=0; i<5;i++) { x = new HashSet() } + for (int i = 0; i < -1; i += 1) { + x = new HashSet() + } x.toInteger() - ''', 'Cannot find matching method java.io.Serializable#toInteger()' + ''', + 'Cannot find matching method java.io.Serializable#toInteger()' } - void testWhileLoopWithNewAssignment() { + void testWhileLoopWithAssignment() { shouldFailWithMessages ''' def x = '123' - while (false) { x = new HashSet() } + while (false) { + x = new HashSet() + } x.toInteger() - ''', 'Cannot find matching method java.io.Serializable#toInteger()' + ''', + 'Cannot find matching method java.io.Serializable#toInteger()' } - void testTernaryWithNewAssignment() { + void testTernaryInitWithAssignment() { shouldFailWithMessages ''' def x = '123' - def cond = false - cond?(x = new HashSet()):3 + def y = (false ? (x = new HashSet()) : 42) x.toInteger() - ''', 'Cannot find matching method java.io.Serializable#toInteger()' + ''', + 'Cannot find matching method java.io.Serializable#toInteger()' } void testFloatSub() {
