You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2020/07/11 02:41:58 UTC

[groovy] branch GROOVY_2_5_X updated (e756438 -> b8872d4)

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

paulk pushed a change to branch GROOVY_2_5_X
in repository https://gitbox.apache.org/repos/asf/groovy.git.


    from e756438  GROOVY-4945, GROOVY-9615: call invokeMissingMethod on MetaClass of super (port to 2_5_X)
     new 59289f0  GROOVY-9288, GROOVY-9292: add test cases
     new e6f6094  GROOVY-9293: add test cases
     new a17e58f  GROOVY-9292, GROOVY-9293: add test cases and minor style changes
     new 959234d  Update tests for GROOVY-9043, GROOVY-9093, GROOVY-9106, et al.(closes #938)
     new b8872d4  GROOVY-9106: fix for same-package check in isDirectAccessAllowed

The 5 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:
 .../classgen/asm/sc/StaticInvocationWriter.java    |   2 +-
 .../classgen/asm/sc/StaticTypesCallSiteWriter.java |  45 ++-
 src/test/groovy/bugs/Groovy9288.groovy             | 339 +++++++++++++++++++
 src/test/groovy/bugs/Groovy9293.groovy             | 359 +++++++++++++++++++++
 .../packageScope/DifferentPackageTest.groovy       | 258 ++++++++++++---
 .../packageScope/PackageScopeTransformTest.groovy  | 244 +++++++++-----
 .../groovy/transform/packageScope/p/One.groovy     |  24 --
 7 files changed, 1096 insertions(+), 175 deletions(-)
 create mode 100644 src/test/groovy/bugs/Groovy9288.groovy
 create mode 100644 src/test/groovy/bugs/Groovy9293.groovy
 delete mode 100644 src/test/org/codehaus/groovy/transform/packageScope/p/One.groovy


[groovy] 02/05: GROOVY-9293: add test cases

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

paulk pushed a commit to branch GROOVY_2_5_X
in repository https://gitbox.apache.org/repos/asf/groovy.git

commit e6f60942930531fdd08ed983772b999acccd0416
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Mon Oct 28 10:51:13 2019 -0500

    GROOVY-9293: add test cases
---
 src/test/groovy/bugs/Groovy9293.groovy | 329 +++++++++++++++++++++++++++++++++
 1 file changed, 329 insertions(+)

diff --git a/src/test/groovy/bugs/Groovy9293.groovy b/src/test/groovy/bugs/Groovy9293.groovy
new file mode 100644
index 0000000..4d66cb1
--- /dev/null
+++ b/src/test/groovy/bugs/Groovy9293.groovy
@@ -0,0 +1,329 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package groovy.bugs
+
+import groovy.test.NotYetImplemented
+import org.junit.Test
+
+import static groovy.test.GroovyAssert.shouldFail
+
+final class Groovy9293 {
+
+    private final GroovyShell shell = new GroovyShell()
+
+    @Test
+    void 'test accessing a package-private super class field inside a closure - same package'() {
+        shell.with {
+            evaluate '''
+                package a
+
+                class A {
+                    @groovy.transform.PackageScope
+                    String superField = 'works'
+                }
+
+                class B extends A {
+                    @groovy.transform.CompileStatic
+                    def test() {
+                        'something'.with {
+                            return superField
+                        }
+                    }
+                }
+
+                def obj = new B()
+                assert obj.test() == "works"
+            '''
+        }
+    }
+
+    @Test
+    void 'test accessing a package-private super class field inside a closure - diff package'() {
+        shouldFail(MissingPropertyException) {
+            shell.with {
+                evaluate '''
+                    package a
+
+                    class A {
+                        @groovy.transform.PackageScope
+                        String superField = 'works'
+                    }
+
+                    assert true
+                '''
+
+                evaluate '''
+                    package b
+
+                    class B extends a.A {
+                        @groovy.transform.CompileStatic
+                        def test() {
+                            'something'.with {
+                                return superField
+                            }
+                        }
+                    }
+
+                    def obj = new B()
+                    assert obj.test() == "works"
+                '''
+            }
+        }
+    }
+
+    @Test
+    void 'test accessing a package-private super class field inside a closure - same package, this qualifier'() {
+        shell.with {
+            evaluate '''
+                package a
+
+                class A {
+                    @groovy.transform.PackageScope
+                    String superField = 'works'
+                }
+
+                class B extends A {
+                    @groovy.transform.CompileStatic
+                    def test() {
+                        'something'.with {
+                            return this.superField
+                        }
+                    }
+                }
+
+                def obj = new B()
+                assert obj.test() == "works"
+            '''
+        }
+    }
+
+    @Test
+    void 'test accessing a package-private super class field inside a closure - diff package, this qualifier'() {
+        shouldFail(MissingPropertyException) {
+            shell.with {
+                evaluate '''
+                    package a
+
+                    class A {
+                        @groovy.transform.PackageScope
+                        String superField = 'works'
+                    }
+
+                    assert true
+                '''
+
+                evaluate '''
+                    package b
+
+                    class B extends a.A {
+                        @groovy.transform.CompileStatic
+                        def test() {
+                            'something'.with {
+                                return this.superField
+                            }
+                        }
+                    }
+
+                    def obj = new B()
+                    assert obj.test() == "works"
+                '''
+            }
+        }
+    }
+
+    @Test
+    void 'test accessing a package-private super class field inside a closure - same package, owner qualifier'() {
+        shell.with {
+            evaluate '''
+                package a
+
+                class A {
+                    @groovy.transform.PackageScope
+                    String superField = 'works'
+                }
+
+                class B extends A {
+                    @groovy.transform.CompileStatic
+                    def test() {
+                        'something'.with {
+                            return owner.superField
+                        }
+                    }
+                }
+
+                def obj = new B()
+                assert obj.test() == "works"
+            '''
+        }
+    }
+
+    @Test @NotYetImplemented // GROOVY-9293
+    void 'test accessing a package-private super class field inside a closure - diff package, owner qualifier'() {
+        shouldFail(MissingPropertyException) {
+            shell.with {
+                evaluate '''
+                    package a
+
+                    class A {
+                        @groovy.transform.PackageScope
+                        String superField = 'works'
+                    }
+
+                    assert true
+                '''
+
+                evaluate '''
+                    package b
+
+                    class B extends a.A {
+                        @groovy.transform.CompileStatic
+                        def test() {
+                            'something'.with {
+                                return owner.superField // Access to b.B#superField is forbidden
+                            }
+                        }
+                    }
+
+                    def obj = new B()
+                    assert obj.test() == "works"
+                '''
+            }
+        }
+    }
+
+    @Test
+    void 'test accessing a package-private super class field inside a closure - same package, delegate qualifier'() {
+        shell.with {
+            evaluate '''
+                package a
+
+                class A {
+                    @groovy.transform.PackageScope
+                    String superField = 'works'
+                }
+
+                class B extends A {
+                    @groovy.transform.CompileStatic
+                    def test() {
+                        with {
+                            return delegate.superField
+                        }
+                    }
+                }
+
+                def obj = new B()
+                assert obj.test() == "works"
+            '''
+        }
+    }
+
+    @Test @NotYetImplemented // GROOVY-9293
+    void 'test accessing a package-private super class field inside a closure - diff package, delegate qualifier'() {
+        shouldFail(MissingPropertyException) {
+            shell.with {
+                evaluate '''
+                    package a
+
+                    class A {
+                        @groovy.transform.PackageScope
+                        String superField = 'works'
+                    }
+
+                    assert true
+                '''
+
+                evaluate '''
+                    package b
+
+                    class B extends a.A {
+                        @groovy.transform.CompileStatic
+                        def test() {
+                            with {
+                                return delegate.superField // Access to b.B#superField is forbidden
+                            }
+                        }
+                    }
+
+                    def obj = new B()
+                    assert obj.test() == "works"
+                '''
+            }
+        }
+    }
+
+    @Test
+    void 'test accessing a package-private super class field inside a closure - same package, thisObject qualifier'() {
+        shell.with {
+            evaluate '''
+                package a
+
+                class A {
+                    @groovy.transform.PackageScope
+                    String superField = 'works'
+                }
+
+                class B extends A {
+                    @groovy.transform.CompileStatic
+                    def test() {
+                        'something'.with {
+                            return thisObject.superField
+                        }
+                    }
+                }
+
+                def obj = new B()
+                assert obj.test() == "works"
+            '''
+        }
+    }
+
+    @Test @NotYetImplemented // GROOVY-9293
+    void 'test accessing a package-private super class field inside a closure - diff package, thisObject qualifier'() {
+        shouldFail(MissingPropertyException) {
+            shell.with {
+                evaluate '''
+                    package a
+
+                    class A {
+                        @groovy.transform.PackageScope
+                        String superField = 'works'
+                    }
+
+                    assert true
+                '''
+
+                evaluate '''
+                    package b
+
+                    class B extends a.A {
+                        @groovy.transform.CompileStatic
+                        def test() {
+                            'something'.with {
+                                return thisObject.superField
+                            }
+                        }
+                    }
+
+                    def obj = new B()
+                    assert obj.test() == "works"
+                '''
+            }
+        }
+    }
+}


[groovy] 04/05: Update tests for GROOVY-9043, GROOVY-9093, GROOVY-9106, et al.(closes #938)

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

paulk pushed a commit to branch GROOVY_2_5_X
in repository https://gitbox.apache.org/repos/asf/groovy.git

commit 959234d0d03cbfe3030f57fc2fd98110a9f5faca
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Sun Jul 14 21:11:03 2019 +0800

    Update tests for GROOVY-9043, GROOVY-9093, GROOVY-9106, et al.(closes #938)
---
 .../packageScope/DifferentPackageTest.groovy       | 247 +++++++++++++++++----
 .../packageScope/PackageScopeTransformTest.groovy  | 244 +++++++++++++-------
 .../groovy/transform/packageScope/p/One.groovy     |  24 --
 3 files changed, 365 insertions(+), 150 deletions(-)

diff --git a/src/test/org/codehaus/groovy/transform/packageScope/DifferentPackageTest.groovy b/src/test/org/codehaus/groovy/transform/packageScope/DifferentPackageTest.groovy
index b41b9c6..a041e6a 100644
--- a/src/test/org/codehaus/groovy/transform/packageScope/DifferentPackageTest.groovy
+++ b/src/test/org/codehaus/groovy/transform/packageScope/DifferentPackageTest.groovy
@@ -18,72 +18,227 @@
  */
 package org.codehaus.groovy.transform.packageScope
 
-import org.codehaus.groovy.control.MultipleCompilationErrorsException
+import org.codehaus.groovy.control.*
+import org.codehaus.groovy.tools.GroovyClass
 
-class DifferentPackageTest extends GroovyTestCase {
-    void _FIXME_testSamePackageShouldSeeInstanceProps() {
-        assertScript '''
-            package org.codehaus.groovy.transform.packageScope.p
+final class DifferentPackageTest extends GroovyTestCase {
 
-            @groovy.transform.CompileStatic
-            class Two extends One {
-                void valSize() {
-                    value.size()
-                }
+    /** Class in package {@code p} with package-private fields {@code value} and {@code CONST}. */
+    private static final String P_DOT_ONE = '''
+        package p
+
+        @groovy.transform.CompileStatic
+        class One {
+            @groovy.transform.PackageScope
+            String value = 'value'
+            @groovy.transform.PackageScope
+            static final int CONST = 42
+        }
+    '''
+
+    private ClassLoader addSources(Map<String, String> sources) {
+        new CompilationUnit().with {
+            sources.each { name, text -> addSource(name + '.groovy', text) }
+            compile(Phases.CLASS_GENERATION)
+
+            classes.each { GroovyClass groovyClass ->
+                classLoader.defineClass(groovyClass.name, groovyClass.bytes)
             }
+            return classLoader
+        }
+    }
+
+    //--------------------------------------------------------------------------
 
-            assert new Two().valSize() == 3
-        '''
+    void testSamePackageShouldSeeInstanceProps1() {
+        def loader = addSources(
+            One: P_DOT_ONE,
+            Two: '''
+                package p
+
+                @groovy.transform.CompileStatic
+                class Two extends One {
+                    int valueSize() {
+                        value.size()
+                    }
+                }
+            ''')
+
+        assert loader.loadClass('p.Two').newInstance().valueSize() == 5
     }
 
-    void _FIXME_testSamePackageShouldSeeStaticProps() {
-        assertScript '''
-            package org.codehaus.groovy.transform.packageScope.p
+    void testSamePackageShouldSeeInstanceProps2() {
+        def loader = addSources(
+            One: P_DOT_ONE,
+            Peer: '''
+                package p
 
-            @groovy.transform.CompileStatic
-            class Three {
-                static void halfNum() {
-                    One.NUM / 2
+                @groovy.transform.CompileStatic
+                class Peer {
+                    int valueSize() {
+                        new One().value.size()
+                    }
                 }
-            }
+            ''')
 
-            assert Three.halfNum() == 21
-        '''
+        assert loader.loadClass('p.Peer').newInstance().valueSize() == 5
     }
 
-    void _FIXME_testDifferentPackageShouldNotSeeInstanceProps() {
-        def message = shouldFail(MultipleCompilationErrorsException, '''
-            package org.codehaus.groovy.transform.packageScope.q
+    void testSamePackageShouldSeeStaticProps1() {
+        def loader = addSources(
+            One: P_DOT_ONE,
+            Two: '''
+                package p
 
-            import org.codehaus.groovy.transform.packageScope.p.One
+                @groovy.transform.CompileStatic
+                class Two extends One {
+                    static def half() {
+                        CONST / 2
+                    }
+                }
+            ''')
+
+        assert loader.loadClass('p.Two').half() == 21
+    }
 
-            @groovy.transform.CompileStatic
-            class Two extends One {
-                void valSize() {
-                    value.size()
+    void testSamePackageShouldSeeStaticProps2() {
+        def loader = addSources(
+            One: P_DOT_ONE,
+            Two: '''
+                package p
+
+                @groovy.transform.CompileStatic
+                class Two extends One {
+                    def half() {
+                        CONST / 2
+                    }
                 }
-            }
+            ''')
 
-            assert new Two().valSize() == 3
-        ''')
-        assert message.matches('(?s).*Access to .*value is forbidden.*')
+        assert loader.loadClass('p.Two').newInstance().half() == 21
     }
 
-    void testDifferentPackageShouldNotSeeStaticProps() {
-        def message = shouldFail(MultipleCompilationErrorsException, '''
-            package org.codehaus.groovy.transform.packageScope.q
+    void testSamePackageShouldSeeStaticProps3() {
+        def loader = addSources(
+            One: P_DOT_ONE,
+            Peer: '''
+                package p
 
-            import org.codehaus.groovy.transform.packageScope.p.One
+                @groovy.transform.CompileStatic
+                class Peer {
+                    static def half() {
+                        One.CONST / 2
+                    }
+                }
+            ''')
+
+        assert loader.loadClass('p.Peer').half() == 21
+    }
 
-            @groovy.transform.CompileStatic
-            class Three {
-                static void halfNum() {
-                    One.NUM / 2
+    void testSamePackageShouldSeeStaticProps4() {
+        def loader = addSources(
+            One: P_DOT_ONE,
+            Peer: '''
+                package p
+
+                @groovy.transform.CompileStatic
+                class Peer {
+                    def half() {
+                        One.CONST / 2
+                    }
                 }
-            }
+            ''')
+
+        assert loader.loadClass('p.Peer').newInstance().half() == 21
+    }
+
+    // GROOVY-9106
+    void _FIXME_testSamePackageShouldSeeStaticProps5() {
+        def loader = addSources(
+            One: P_DOT_ONE,
+            Two: '''
+                package q
+
+                @groovy.transform.CompileStatic
+                class Two extends p.One {
+                }
+            ''',
+            Peer: '''\
+                package p
+
+                @groovy.transform.CompileStatic
+                class Peer {
+                    static def half() {
+                        (q.Two.CONST / 2) // indirect access
+                    }
+                }
+            ''')
+
+        assert loader.loadClass('p.Peer').half() == 21
+    }
+
+    // GROOVY-9093
+    void _FIXME_testDifferentPackageShouldNotSeeInstanceProps() {
+        def err = shouldFail CompilationFailedException, {
+            def loader = addSources(
+                One: P_DOT_ONE,
+                Two: '''
+                    package q
+
+                    @groovy.transform.CompileStatic
+                    class Two extends p.One {
+                        int valueSize() {
+                            value.size() // not visible
+                        }
+                    }
+                ''')
+            // TODO: Don't need this once compiler errors
+            assert loader.loadClass('q.Two').newInstance().valueSize() == 5
+        }
+
+        assert err =~ / Access to ... value is forbidden /
+    }
+
+    // GROOVY-9093
+    void _FIXME_testDifferentPackageShouldNotSeeStaticProps1() {
+        def err = shouldFail CompilationFailedException, {
+            def loader = addSources(
+                One: P_DOT_ONE,
+                Two: '''
+                    package q
+
+                    @groovy.transform.CompileStatic
+                    class Two extends p.One {
+                        static def half() {
+                            (CONST / 2) // not visible
+                        }
+                    }
+                ''')
+            // TODO: Don't need this once compiler errors
+            assert loader.loadClass('q.Two').half() == 21
+        }
+
+        assert err =~ / Access to p.One#CONST is forbidden /
+    }
+
+    void testDifferentPackageShouldNotSeeStaticProps2() {
+        def err = shouldFail CompilationFailedException, {
+            addSources(
+                One: P_DOT_ONE,
+                Other: '''
+                    package q
+
+                    import p.One
+
+                    @groovy.transform.CompileStatic
+                    class Other {
+                        static def half() {
+                            (One.CONST / 2) // not visible
+                        }
+                    }
+                ''')
+        }
 
-            assert Three.halfNum() == 21
-        ''')
-        assert message.matches('(?s).*Access to .*One#NUM is forbidden.*')
+        assert err =~ / Access to p.One#CONST is forbidden /
     }
 }
diff --git a/src/test/org/codehaus/groovy/transform/packageScope/PackageScopeTransformTest.groovy b/src/test/org/codehaus/groovy/transform/packageScope/PackageScopeTransformTest.groovy
index 83f8048..12f3a5e 100644
--- a/src/test/org/codehaus/groovy/transform/packageScope/PackageScopeTransformTest.groovy
+++ b/src/test/org/codehaus/groovy/transform/packageScope/PackageScopeTransformTest.groovy
@@ -18,107 +18,191 @@
  */
 package org.codehaus.groovy.transform.packageScope
 
-import java.lang.reflect.Modifier
+import groovy.transform.CompileStatic
+import org.junit.Test
 
-class PackageScopeTransformTest extends GroovyShellTestCase {
-    // GROOVY-9043
-    void testPackagePrivateAccessFromInnerClassCS() {
+import static groovy.test.GroovyAssert.assertScript
+
+@CompileStatic
+final class PackageScopeTransformTest {
+
+    @Test
+    void testPackageScope1() {
         assertScript '''
-            import groovy.transform.CompileStatic
             import groovy.transform.PackageScope
-            @CompileStatic
-            class Test {
-                @PackageScope
-                static final String S = 'S'
-                static private final String T = 'T'
-                static protected final String U = 'U'
-                static class Inner {
-                    String method() {
-                        S + T + U
-                    }
-                }
+            import static java.lang.reflect.Modifier.*
+
+            class A {
+                String x
+            }
+            @PackageScope class B {
+                String x
             }
 
-            assert new Test.Inner().method() == 'STU'
+            assert isPublic(A.modifiers)
+            assert !isPublic(B.modifiers) && !isPrivate(B.modifiers) && !isProtected(B.modifiers)
+
+            assert isPublic(A.getDeclaredConstructor().modifiers)
+            assert isPublic(B.getDeclaredConstructor().modifiers)
+
+            assert isPrivate(A.getDeclaredField('x').modifiers)
+            assert isPrivate(A.getDeclaredField('x').modifiers)
+
+            assert isPublic(A.getDeclaredMethod('getX').modifiers)
+            assert isPublic(B.getDeclaredMethod('getX').modifiers)
+
+            assert isPublic(A.getDeclaredMethod('setX', String).modifiers)
+            assert isPublic(B.getDeclaredMethod('setX', String).modifiers)
         '''
     }
 
-    void testImmutable() {
-        def objects = evaluate("""
+    @Test
+    void testPackageScope2() {
+        assertScript '''
             import groovy.transform.PackageScope
-            import static groovy.transform.PackageScopeTarget.FIELDS
-            class Control {
-                String x
-                def method() {}
+            import static java.lang.reflect.Modifier.*
+            import static groovy.test.GroovyAssert.shouldFail
+
+            class C {
+                @PackageScope C() {}
+                @PackageScope String x
+                @PackageScope def method() {}
+            }
+
+            boolean isPackagePrivate(modifiers) {
+                !isPublic(modifiers) && !isPrivate(modifiers) && !isProtected(modifiers)
             }
-            @PackageScope(FIELDS) class Foo {
+
+            assert isPublic(C.modifiers)
+
+            assert isPackagePrivate(C.getDeclaredConstructor().modifiers)
+
+            assert isPackagePrivate(C.getDeclaredField('x').modifiers)
+
+            assert isPackagePrivate(C.getDeclaredMethod('method').modifiers)
+
+            shouldFail(NoSuchMethodException) {
+                C.getDeclaredMethod('getX')
+                C.getDeclaredMethod('setX', String)
+            }
+        '''
+    }
+
+    @Test
+    void testPackageScope3() {
+        assertScript '''
+            import groovy.transform.PackageScope
+            import static java.lang.reflect.Modifier.*
+            import static groovy.test.GroovyAssert.shouldFail
+            import static groovy.transform.PackageScopeTarget.*
+
+            @PackageScope(FIELDS) class C {
+                C() {}
                 String x
                 def method() {}
             }
-            class Bar {
-                Bar() {}
-                @PackageScope Bar(String x) { this.x = x }
-                @PackageScope String x
-                @PackageScope def method() {}
+
+            boolean isPackagePrivate(modifiers) {
+                !isPublic(modifiers) && !isPrivate(modifiers) && !isProtected(modifiers)
+            }
+
+            assert isPublic(C.modifiers)
+
+            assert isPublic(C.getDeclaredConstructor().modifiers)
+
+            assert isPackagePrivate(C.getDeclaredField('x').modifiers)
+
+            assert isPublic(C.getDeclaredMethod('method').modifiers)
+
+            shouldFail(NoSuchMethodException) {
+                C.getDeclaredMethod('getX')
+                C.getDeclaredMethod('setX', String)
             }
-            @PackageScope class Baz {
+        '''
+    }
+
+    @Test
+    void testPackageScope4() {
+        assertScript '''
+            import groovy.transform.PackageScope
+            import static java.lang.reflect.Modifier.*
+            import static groovy.test.GroovyAssert.shouldFail
+            import static groovy.transform.PackageScopeTarget.*
+
+            @PackageScope(METHODS) class C {
+                C() {}
                 String x
                 def method() {}
             }
-            [new Control(), new Foo(), new Bar(), new Baz()]
-        """)
-        objects*.class.each { c ->
-            def methodNames = c.methods.name
-            if (c.name == 'Control' || c.name == 'Baz') {
-                assert methodNames.contains('getX')
-                assert methodNames.contains('setX')
-            } else {
-                assert !methodNames.contains('getX')
-                assert !methodNames.contains('setX')
-            }
-            def xField = c.declaredFields.find{ it.name == 'x' }
-            assert xField
-            if (c.name == 'Control' || c.name == 'Baz') {
-                assert Modifier.isPrivate(xField.modifiers)
-            } else {
-                assert !Modifier.isPrivate(xField.modifiers)
-                assert !Modifier.isPublic(xField.modifiers)
-                assert !Modifier.isProtected(xField.modifiers)
+
+            boolean isPackagePrivate(modifiers) {
+                !isPublic(modifiers) && !isPrivate(modifiers) && !isProtected(modifiers)
             }
-            def method = c.declaredMethods.find{ it.name == 'method' }
-            assert method
-            if (c.name == 'Bar') {
-                assert !Modifier.isPrivate(method.modifiers)
-                assert !Modifier.isPublic(method.modifiers)
-                assert !Modifier.isProtected(method.modifiers)
-            } else {
-                assert Modifier.isPublic(method.modifiers)
+
+            assert isPublic(C.modifiers)
+
+            assert isPublic(C.getDeclaredConstructor().modifiers)
+
+            assert isPrivate(C.getDeclaredField('x').modifiers)
+            assert isPublic(C.getDeclaredMethod('getX').modifiers)
+            assert isPublic(C.getDeclaredMethod('setX', String).modifiers)
+
+            assert isPackagePrivate(C.getDeclaredMethod('method').modifiers)
+        '''
+    }
+
+    @Test
+    void testPackageScope5() {
+        assertScript '''
+            import groovy.transform.PackageScope
+            import static java.lang.reflect.Modifier.*
+            import static groovy.test.GroovyAssert.shouldFail
+            import static groovy.transform.PackageScopeTarget.*
+
+            @PackageScope([CLASS, CONSTRUCTORS, METHODS]) class C {
+                C() {}
+                String x
+                def method() {}
+                static class D {}
             }
-            if (c.name == 'Baz') {
-                assert !Modifier.isPrivate(c.modifiers)
-                assert !Modifier.isPublic(c.modifiers)
-                assert !Modifier.isProtected(c.modifiers)
-            } else {
-                assert Modifier.isPublic(c.modifiers)
+
+            boolean isPackagePrivate(modifiers) {
+                !isPublic(modifiers) && !isPrivate(modifiers) && !isProtected(modifiers)
             }
-            def cons = c.declaredConstructors
-            if (c.name == 'Bar') {
-                assert cons.size() == 2
-                cons.each { con ->
-                    if (con.parameterTypes*.name == []) {
-                        assert Modifier.isPublic(con.modifiers)
-                    } else {
-                        assert con.parameterTypes*.name == ['java.lang.String']
-                        assert !Modifier.isPrivate(con.modifiers)
-                        assert !Modifier.isPublic(con.modifiers)
-                        assert !Modifier.isProtected(con.modifiers)
-                    }
 
+            assert isPackagePrivate(C.modifiers)
+
+            assert isPackagePrivate(C.getDeclaredConstructor().modifiers)
+
+            assert isPrivate(C.getDeclaredField('x').modifiers)
+            assert isPublic(C.getDeclaredMethod('getX').modifiers)
+            assert isPublic(C.getDeclaredMethod('setX', String).modifiers)
+
+            assert isPackagePrivate(C.getDeclaredMethod('method').modifiers)
+
+            assert isPublic(C.getDeclaredClasses()[0].modifiers) // not transitive
+        '''
+    }
+
+    @Test // GROOVY-9043
+    void testStaticFieldAccessFromInnerClassCS() {
+        assertScript '''
+            import groovy.transform.CompileStatic
+            import groovy.transform.PackageScope
+
+            @CompileStatic
+            class Test {
+                @PackageScope static final String S = 'S'
+                protected static final String T = 'T'
+                private static final String U = 'U'
+                static class Inner {
+                    String method() {
+                        S + T + U
+                    }
                 }
-            } else {
-                assert cons.size() == 1
-                assert Modifier.isPublic(cons[0].modifiers)
             }
-        }
+
+            assert new Test.Inner().method() == 'STU'
+        '''
     }
-}
\ No newline at end of file
+}
diff --git a/src/test/org/codehaus/groovy/transform/packageScope/p/One.groovy b/src/test/org/codehaus/groovy/transform/packageScope/p/One.groovy
deleted file mode 100644
index f4fc0e6..0000000
--- a/src/test/org/codehaus/groovy/transform/packageScope/p/One.groovy
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- *  Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you under the Apache License, Version 2.0 (the
- *  "License"); you may not use this file except in compliance
- *  with the License.  You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License.
- */
-package org.codehaus.groovy.transform.packageScope.p
-
-class One {
-    @groovy.transform.PackageScope final String value = 'val'
-    @groovy.transform.PackageScope final static Integer NUM = 42
-}


[groovy] 03/05: GROOVY-9292, GROOVY-9293: add test cases and minor style changes

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

paulk pushed a commit to branch GROOVY_2_5_X
in repository https://gitbox.apache.org/repos/asf/groovy.git

commit a17e58f95aada11ad2f52082dd140d92b8e3d981
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Mon Oct 28 11:35:15 2019 -0500

    GROOVY-9292, GROOVY-9293: add test cases and minor style changes
---
 src/test/groovy/bugs/Groovy9288.groovy | 408 ++++++++++++++++++---------------
 src/test/groovy/bugs/Groovy9293.groovy | 370 ++++++++++++++++--------------
 2 files changed, 420 insertions(+), 358 deletions(-)

diff --git a/src/test/groovy/bugs/Groovy9288.groovy b/src/test/groovy/bugs/Groovy9288.groovy
index a09af73..f2b5bee 100644
--- a/src/test/groovy/bugs/Groovy9288.groovy
+++ b/src/test/groovy/bugs/Groovy9288.groovy
@@ -27,281 +27,313 @@ final class Groovy9288 {
 
     @Test
     void 'test accessing a protected super class field inside a closure - same package'() {
-        shell.with {
-            evaluate '''
-                package a
-
-                class A {
-                    protected String superField = 'works'
-                }
-
-                class B extends A {
-                    @groovy.transform.CompileStatic
-                    def test() {
-                        'something'.with {
-                            return superField
-                        }
+        shell.evaluate '''
+            package a
+
+            class A {
+                protected String superField = 'works'
+            }
+
+            class B extends A {
+                @groovy.transform.CompileStatic
+                def test() {
+                    'something'.with {
+                        return superField
                     }
                 }
+            }
 
-                def obj = new B()
-                assert obj.test() == "works"
-            '''
-        }
+            def obj = new B()
+            assert obj.test() == "works"
+        '''
     }
 
     @Test
     void 'test accessing a protected super class field inside a closure - diff package'() {
-        shell.with {
-            evaluate '''
-                package a
+        shell.evaluate '''
+            package a
 
-                class A {
-                    protected String superField = 'works'
-                }
+            class A {
+                protected String superField = 'works'
+            }
 
-                assert true
-            '''
+            assert true
+        '''
 
-            evaluate '''
-                package b
+        shell.evaluate '''
+            package b
 
-                class B extends a.A {
-                    @groovy.transform.CompileStatic
-                    def test() {
-                        'something'.with {
-                            return superField
-                        }
+            class B extends a.A {
+                @groovy.transform.CompileStatic
+                def test() {
+                    'something'.with {
+                        return superField
                     }
                 }
+            }
 
-                def obj = new B()
-                assert obj.test() == "works"
-            '''
-        }
+            def obj = new B()
+            assert obj.test() == "works"
+        '''
     }
 
     @Test
-    void 'test accessing a protected super class field inside a closure - same package, this qualifier'() {
-        shell.with {
-            evaluate '''
-                package a
+    void 'test accessing a protected super class field inside a closure - same package, it qualifier'() {
+        shell.evaluate '''
+            package a
+
+            class A {
+                protected String superField = 'works'
+            }
+
+            class B extends A {
+                @groovy.transform.CompileStatic
+                def test() {
+                    with {
+                        return it.superField
+                    }
+                }
+            }
+
+            def obj = new B()
+            assert obj.test() == "works"
+        '''
+    }
+
+    @Test @NotYetImplemented // GROOVY-9292
+    void 'test accessing a protected super class field inside a closure - diff package, it qualifier'() {
+        shell.evaluate '''
+            package a
+
+            class A {
+                protected String superField = 'works'
+            }
 
-                class A {
-                    protected String superField = 'works'
+            assert true
+        '''
+
+        shell.evaluate '''
+            package b
+
+            class B extends a.A {
+                @groovy.transform.CompileStatic
+                def test() {
+                    with {
+                        return it.superField
+                    }
                 }
+            }
+
+            def obj = new B()
+            assert obj.test() == "works"
+        '''
+    }
 
-                class B extends A {
-                    @groovy.transform.CompileStatic
-                    def test() {
-                        'something'.with {
-                            return this.superField
-                        }
+    @Test
+    void 'test accessing a protected super class field inside a closure - same package, this qualifier'() {
+        shell.evaluate '''
+            package a
+
+            class A {
+                protected String superField = 'works'
+            }
+
+            class B extends A {
+                @groovy.transform.CompileStatic
+                def test() {
+                    'something'.with {
+                        return this.superField
                     }
                 }
+            }
 
-                def obj = new B()
-                assert obj.test() == "works"
-            '''
-        }
+            def obj = new B()
+            assert obj.test() == "works"
+        '''
     }
 
     @Test
     void 'test accessing a protected super class field inside a closure - diff package, this qualifier'() {
-        shell.with {
-            evaluate '''
-                package a
+        shell.evaluate '''
+            package a
 
-                class A {
-                    protected String superField = 'works'
-                }
+            class A {
+                protected String superField = 'works'
+            }
 
-                assert true
-            '''
+            assert true
+        '''
 
-            evaluate '''
-                package b
+        shell.evaluate '''
+            package b
 
-                class B extends a.A {
-                    @groovy.transform.CompileStatic
-                    def test() {
-                        'something'.with {
-                            return this.superField
-                        }
+            class B extends a.A {
+                @groovy.transform.CompileStatic
+                def test() {
+                    'something'.with {
+                        return this.superField
                     }
                 }
+            }
 
-                def obj = new B()
-                assert obj.test() == "works"
-            '''
-        }
+            def obj = new B()
+            assert obj.test() == "works"
+        '''
     }
 
     @Test
     void 'test accessing a protected super class field inside a closure - same package, owner qualifier'() {
-        shell.with {
-            evaluate '''
-                package a
-
-                class A {
-                    protected String superField = 'works'
-                }
-
-                class B extends A {
-                    @groovy.transform.CompileStatic
-                    def test() {
-                        'something'.with {
-                            return owner.superField
-                        }
+        shell.evaluate '''
+            package a
+
+            class A {
+                protected String superField = 'works'
+            }
+
+            class B extends A {
+                @groovy.transform.CompileStatic
+                def test() {
+                    'something'.with {
+                        return owner.superField
                     }
                 }
+            }
 
-                def obj = new B()
-                assert obj.test() == "works"
-            '''
-        }
+            def obj = new B()
+            assert obj.test() == "works"
+        '''
     }
 
     @Test @NotYetImplemented // GROOVY-9292
     void 'test accessing a protected super class field inside a closure - diff package, owner qualifier'() {
-        shell.with {
-            evaluate '''
-                package a
+        shell.evaluate '''
+            package a
 
-                class A {
-                    protected String superField = 'works'
-                }
+            class A {
+                protected String superField = 'works'
+            }
 
-                assert true
-            '''
+            assert true
+        '''
 
-            evaluate '''
-                package b
+        shell.evaluate '''
+            package b
 
-                class B extends a.A {
-                    @groovy.transform.CompileStatic
-                    def test() {
-                        'something'.with {
-                            return owner.superField
-                        }
+            class B extends a.A {
+                @groovy.transform.CompileStatic
+                def test() {
+                    'something'.with {
+                        return owner.superField
                     }
                 }
+            }
 
-                def obj = new B()
-                assert obj.test() == "works"
-            '''
-        }
+            def obj = new B()
+            assert obj.test() == "works"
+        '''
     }
 
     @Test
     void 'test accessing a protected super class field inside a closure - same package, delegate qualifier'() {
-        shell.with {
-            evaluate '''
-                package a
-
-                class A {
-                    protected String superField = 'works'
-                }
-
-                class B extends A {
-                    @groovy.transform.CompileStatic
-                    def test() {
-                        with {
-                            return delegate.superField
-                        }
+        shell.evaluate '''
+            package a
+
+            class A {
+                protected String superField = 'works'
+            }
+
+            class B extends A {
+                @groovy.transform.CompileStatic
+                def test() {
+                    with {
+                        return delegate.superField
                     }
                 }
+            }
 
-                def obj = new B()
-                assert obj.test() == "works"
-            '''
-        }
+            def obj = new B()
+            assert obj.test() == "works"
+        '''
     }
 
     @Test @NotYetImplemented // GROOVY-9292
     void 'test accessing a protected super class field inside a closure - diff package, delegate qualifier'() {
-        shell.with {
-            evaluate '''
-                package a
+        shell.evaluate '''
+            package a
 
-                class A {
-                    protected String superField = 'works'
-                }
+            class A {
+                protected String superField = 'works'
+            }
 
-                assert true
-            '''
+            assert true
+        '''
 
-            evaluate '''
-                package b
+        shell.evaluate '''
+            package b
 
-                class B extends a.A {
-                    @groovy.transform.CompileStatic
-                    def test() {
-                        with {
-                            return delegate.superField
-                        }
+            class B extends a.A {
+                @groovy.transform.CompileStatic
+                def test() {
+                    with {
+                        return delegate.superField
                     }
                 }
+            }
 
-                def obj = new B()
-                assert obj.test() == "works"
-            '''
-        }
+            def obj = new B()
+            assert obj.test() == "works"
+        '''
     }
 
     @Test
     void 'test accessing a protected super class field inside a closure - same package, thisObject qualifier'() {
-        shell.with {
-            evaluate '''
-                package a
-
-                class A {
-                    protected String superField = 'works'
-                }
-
-                class B extends A {
-                    @groovy.transform.CompileStatic
-                    def test() {
-                        'something'.with {
-                            return thisObject.superField
-                        }
+        shell.evaluate '''
+            package a
+
+            class A {
+                protected String superField = 'works'
+            }
+
+            class B extends A {
+                @groovy.transform.CompileStatic
+                def test() {
+                    'something'.with {
+                        return thisObject.superField
                     }
                 }
+            }
 
-                def obj = new B()
-                assert obj.test() == "works"
-            '''
-        }
+            def obj = new B()
+            assert obj.test() == "works"
+        '''
     }
 
     @Test @NotYetImplemented // GROOVY-9292
     void 'test accessing a protected super class field inside a closure - diff package, thisObject qualifier'() {
-        shell.with {
-            evaluate '''
-                package a
+        shell.evaluate '''
+            package a
 
-                class A {
-                    protected String superField = 'works'
-                }
+            class A {
+                protected String superField = 'works'
+            }
 
-                assert true
-            '''
+            assert true
+        '''
 
-            evaluate '''
-                package b
+        shell.evaluate '''
+            package b
 
-                class B extends a.A {
-                    @groovy.transform.CompileStatic
-                    def test() {
-                        'something'.with {
-                            return thisObject.superField
-                        }
+            class B extends a.A {
+                @groovy.transform.CompileStatic
+                def test() {
+                    'something'.with {
+                        return thisObject.superField
                     }
                 }
+            }
 
-                def obj = new B()
-                assert obj.test() == "works"
-            '''
-        }
+            def obj = new B()
+            assert obj.test() == "works"
+        '''
     }
 }
diff --git a/src/test/groovy/bugs/Groovy9293.groovy b/src/test/groovy/bugs/Groovy9293.groovy
index 4d66cb1..268e5ea 100644
--- a/src/test/groovy/bugs/Groovy9293.groovy
+++ b/src/test/groovy/bugs/Groovy9293.groovy
@@ -29,8 +29,32 @@ final class Groovy9293 {
 
     @Test
     void 'test accessing a package-private super class field inside a closure - same package'() {
-        shell.with {
-            evaluate '''
+        shell.evaluate '''
+            package a
+
+            class A {
+                @groovy.transform.PackageScope
+                String superField = 'works'
+            }
+
+            class B extends A {
+                @groovy.transform.CompileStatic
+                def test() {
+                    'something'.with {
+                        return superField
+                    }
+                }
+            }
+
+            def obj = new B()
+            assert obj.test() == "works"
+        '''
+    }
+
+    @Test
+    void 'test accessing a package-private super class field inside a closure - diff package'() {
+        shouldFail(MissingPropertyException) {
+            shell.evaluate '''
                 package a
 
                 class A {
@@ -38,7 +62,13 @@ final class Groovy9293 {
                     String superField = 'works'
                 }
 
-                class B extends A {
+                assert true
+            '''
+
+            shell.evaluate '''
+                package b
+
+                class B extends a.A {
                     @groovy.transform.CompileStatic
                     def test() {
                         'something'.with {
@@ -47,50 +77,39 @@ final class Groovy9293 {
                     }
                 }
 
-                def obj = new B()
-                assert obj.test() == "works"
+                new B().test()
             '''
         }
     }
 
     @Test
-    void 'test accessing a package-private super class field inside a closure - diff package'() {
-        shouldFail(MissingPropertyException) {
-            shell.with {
-                evaluate '''
-                    package a
+    void 'test accessing a package-private super class field inside a closure - same package, it qualifier'() {
+        shell.evaluate '''
+            package a
 
-                    class A {
-                        @groovy.transform.PackageScope
-                        String superField = 'works'
-                    }
-
-                    assert true
-                '''
-
-                evaluate '''
-                    package b
+            class A {
+                @groovy.transform.PackageScope
+                String superField = 'works'
+            }
 
-                    class B extends a.A {
-                        @groovy.transform.CompileStatic
-                        def test() {
-                            'something'.with {
-                                return superField
-                            }
-                        }
+            class B extends A {
+                @groovy.transform.CompileStatic
+                def test() {
+                    with {
+                        return it.superField
                     }
-
-                    def obj = new B()
-                    assert obj.test() == "works"
-                '''
+                }
             }
-        }
+
+            def obj = new B()
+            assert obj.test() == "works"
+        '''
     }
 
-    @Test
-    void 'test accessing a package-private super class field inside a closure - same package, this qualifier'() {
-        shell.with {
-            evaluate '''
+    @Test @NotYetImplemented // GROOVY-9293
+    void 'test accessing a package-private super class field inside a closure - diff package, it qualifier'() {
+        shouldFail(MissingPropertyException) {
+            shell.evaluate '''
                 package a
 
                 class A {
@@ -98,59 +117,54 @@ final class Groovy9293 {
                     String superField = 'works'
                 }
 
-                class B extends A {
+                assert true
+            '''
+
+            shell.evaluate '''
+                package b
+
+                class B extends a.A {
                     @groovy.transform.CompileStatic
                     def test() {
-                        'something'.with {
-                            return this.superField
+                        with {
+                            return it.superField
                         }
                     }
                 }
 
-                def obj = new B()
-                assert obj.test() == "works"
+                new B().test()
             '''
         }
     }
 
     @Test
-    void 'test accessing a package-private super class field inside a closure - diff package, this qualifier'() {
-        shouldFail(MissingPropertyException) {
-            shell.with {
-                evaluate '''
-                    package a
-
-                    class A {
-                        @groovy.transform.PackageScope
-                        String superField = 'works'
-                    }
-
-                    assert true
-                '''
+    void 'test accessing a package-private super class field inside a closure - same package, this qualifier'() {
+        shell.evaluate '''
+            package a
 
-                evaluate '''
-                    package b
+            class A {
+                @groovy.transform.PackageScope
+                String superField = 'works'
+            }
 
-                    class B extends a.A {
-                        @groovy.transform.CompileStatic
-                        def test() {
-                            'something'.with {
-                                return this.superField
-                            }
-                        }
+            class B extends A {
+                @groovy.transform.CompileStatic
+                def test() {
+                    'something'.with {
+                        return this.superField
                     }
-
-                    def obj = new B()
-                    assert obj.test() == "works"
-                '''
+                }
             }
-        }
+
+            def obj = new B()
+            assert obj.test() == "works"
+        '''
     }
 
     @Test
-    void 'test accessing a package-private super class field inside a closure - same package, owner qualifier'() {
-        shell.with {
-            evaluate '''
+    void 'test accessing a package-private super class field inside a closure - diff package, this qualifier'() {
+        shouldFail(MissingPropertyException) {
+            shell.evaluate '''
                 package a
 
                 class A {
@@ -158,59 +172,54 @@ final class Groovy9293 {
                     String superField = 'works'
                 }
 
-                class B extends A {
+                assert true
+            '''
+
+            shell.evaluate '''
+                package b
+
+                class B extends a.A {
                     @groovy.transform.CompileStatic
                     def test() {
                         'something'.with {
-                            return owner.superField
+                            return this.superField
                         }
                     }
                 }
 
-                def obj = new B()
-                assert obj.test() == "works"
+                new B().test()
             '''
         }
     }
 
-    @Test @NotYetImplemented // GROOVY-9293
-    void 'test accessing a package-private super class field inside a closure - diff package, owner qualifier'() {
-        shouldFail(MissingPropertyException) {
-            shell.with {
-                evaluate '''
-                    package a
-
-                    class A {
-                        @groovy.transform.PackageScope
-                        String superField = 'works'
-                    }
-
-                    assert true
-                '''
+    @Test
+    void 'test accessing a package-private super class field inside a closure - same package, owner qualifier'() {
+        shell.evaluate '''
+            package a
 
-                evaluate '''
-                    package b
+            class A {
+                @groovy.transform.PackageScope
+                String superField = 'works'
+            }
 
-                    class B extends a.A {
-                        @groovy.transform.CompileStatic
-                        def test() {
-                            'something'.with {
-                                return owner.superField // Access to b.B#superField is forbidden
-                            }
-                        }
+            class B extends A {
+                @groovy.transform.CompileStatic
+                def test() {
+                    'something'.with {
+                        return owner.superField
                     }
-
-                    def obj = new B()
-                    assert obj.test() == "works"
-                '''
+                }
             }
-        }
+
+            def obj = new B()
+            assert obj.test() == "works"
+        '''
     }
 
-    @Test
-    void 'test accessing a package-private super class field inside a closure - same package, delegate qualifier'() {
-        shell.with {
-            evaluate '''
+    @Test @NotYetImplemented // GROOVY-9293
+    void 'test accessing a package-private super class field inside a closure - diff package, owner qualifier'() {
+        shouldFail(MissingPropertyException) {
+            shell.evaluate '''
                 package a
 
                 class A {
@@ -218,59 +227,54 @@ final class Groovy9293 {
                     String superField = 'works'
                 }
 
-                class B extends A {
+                assert true
+            '''
+
+            shell.evaluate '''
+                package b
+
+                class B extends a.A {
                     @groovy.transform.CompileStatic
                     def test() {
-                        with {
-                            return delegate.superField
+                        'something'.with {
+                            return owner.superField
                         }
                     }
                 }
 
-                def obj = new B()
-                assert obj.test() == "works"
+                new B().test()
             '''
         }
     }
 
-    @Test @NotYetImplemented // GROOVY-9293
-    void 'test accessing a package-private super class field inside a closure - diff package, delegate qualifier'() {
-        shouldFail(MissingPropertyException) {
-            shell.with {
-                evaluate '''
-                    package a
-
-                    class A {
-                        @groovy.transform.PackageScope
-                        String superField = 'works'
-                    }
-
-                    assert true
-                '''
+    @Test
+    void 'test accessing a package-private super class field inside a closure - same package, delegate qualifier'() {
+        shell.evaluate '''
+            package a
 
-                evaluate '''
-                    package b
+            class A {
+                @groovy.transform.PackageScope
+                String superField = 'works'
+            }
 
-                    class B extends a.A {
-                        @groovy.transform.CompileStatic
-                        def test() {
-                            with {
-                                return delegate.superField // Access to b.B#superField is forbidden
-                            }
-                        }
+            class B extends A {
+                @groovy.transform.CompileStatic
+                def test() {
+                    with {
+                        return delegate.superField
                     }
-
-                    def obj = new B()
-                    assert obj.test() == "works"
-                '''
+                }
             }
-        }
+
+            def obj = new B()
+            assert obj.test() == "works"
+        '''
     }
 
-    @Test
-    void 'test accessing a package-private super class field inside a closure - same package, thisObject qualifier'() {
-        shell.with {
-            evaluate '''
+    @Test @NotYetImplemented // GROOVY-9293
+    void 'test accessing a package-private super class field inside a closure - diff package, delegate qualifier'() {
+        shouldFail(MissingPropertyException) {
+            shell.evaluate '''
                 package a
 
                 class A {
@@ -278,52 +282,78 @@ final class Groovy9293 {
                     String superField = 'works'
                 }
 
-                class B extends A {
+                assert true
+            '''
+
+            shell.evaluate '''
+                package b
+
+                class B extends a.A {
                     @groovy.transform.CompileStatic
                     def test() {
-                        'something'.with {
-                            return thisObject.superField
+                        with {
+                            return delegate.superField
                         }
                     }
                 }
 
-                def obj = new B()
-                assert obj.test() == "works"
+                new B().test()
             '''
         }
     }
 
+    @Test
+    void 'test accessing a package-private super class field inside a closure - same package, thisObject qualifier'() {
+        shell.evaluate '''
+            package a
+
+            class A {
+                @groovy.transform.PackageScope
+                String superField = 'works'
+            }
+
+            class B extends A {
+                @groovy.transform.CompileStatic
+                def test() {
+                    'something'.with {
+                        return thisObject.superField
+                    }
+                }
+            }
+
+            def obj = new B()
+            assert obj.test() == "works"
+        '''
+    }
+
     @Test @NotYetImplemented // GROOVY-9293
     void 'test accessing a package-private super class field inside a closure - diff package, thisObject qualifier'() {
         shouldFail(MissingPropertyException) {
-            shell.with {
-                evaluate '''
-                    package a
+            shell.evaluate '''
+                package a
 
-                    class A {
-                        @groovy.transform.PackageScope
-                        String superField = 'works'
-                    }
+                class A {
+                    @groovy.transform.PackageScope
+                    String superField = 'works'
+                }
 
-                    assert true
-                '''
+                assert true
+            '''
 
-                evaluate '''
-                    package b
+            shell.evaluate '''
+                package b
 
-                    class B extends a.A {
-                        @groovy.transform.CompileStatic
-                        def test() {
-                            'something'.with {
-                                return thisObject.superField
-                            }
+                class B extends a.A {
+                    @groovy.transform.CompileStatic
+                    def test() {
+                        'something'.with {
+                            return thisObject.superField
                         }
                     }
+                }
 
-                    def obj = new B()
-                    assert obj.test() == "works"
-                '''
-            }
+                new B().test()
+            '''
         }
     }
 }


[groovy] 05/05: GROOVY-9106: fix for same-package check in isDirectAccessAllowed

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

paulk pushed a commit to branch GROOVY_2_5_X
in repository https://gitbox.apache.org/repos/asf/groovy.git

commit b8872d4fe04fb39dd6584348851d24d98973cf38
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Sun Jul 14 09:59:32 2019 -0500

    GROOVY-9106: fix for same-package check in isDirectAccessAllowed
---
 .../classgen/asm/sc/StaticInvocationWriter.java    |  2 +-
 .../classgen/asm/sc/StaticTypesCallSiteWriter.java | 45 ++++++++++------------
 .../packageScope/DifferentPackageTest.groovy       | 27 +++++++++----
 3 files changed, 41 insertions(+), 33 deletions(-)

diff --git a/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticInvocationWriter.java b/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticInvocationWriter.java
index bb957eb..352fa2b 100644
--- a/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticInvocationWriter.java
+++ b/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticInvocationWriter.java
@@ -665,7 +665,7 @@ public class StaticInvocationWriter extends InvocationWriter {
                 if (pname!=null && callSiteWriter instanceof StaticTypesCallSiteWriter) {
                     StaticTypesCallSiteWriter stcsw = (StaticTypesCallSiteWriter) callSiteWriter;
                     TypeChooser typeChooser = controller.getTypeChooser();
-                    if (stcsw.makeGetField(receiver, typeChooser.resolveType(receiver, controller.getClassNode()), pname, safe, false, true)) {
+                    if (stcsw.makeGetField(receiver, typeChooser.resolveType(receiver, controller.getClassNode()), pname, safe, false)) {
                         return;
                     }
                 }
diff --git a/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticTypesCallSiteWriter.java b/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticTypesCallSiteWriter.java
index 196e5e0..575a365 100644
--- a/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticTypesCallSiteWriter.java
+++ b/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticTypesCallSiteWriter.java
@@ -94,15 +94,14 @@ import static org.codehaus.groovy.transform.stc.StaticTypeCheckingSupport.isClas
  */
 public class StaticTypesCallSiteWriter extends CallSiteWriter implements Opcodes {
 
-    private static final ClassNode INVOKERHELPER_TYPE = ClassHelper.make(InvokerHelper.class);
-    private static final MethodNode GROOVYOBJECT_GETPROPERTY_METHOD = GROOVY_OBJECT_TYPE.getMethod("getProperty", new Parameter[]{new Parameter(STRING_TYPE, "propertyName")});
-    private static final MethodNode INVOKERHELPER_GETPROPERTY_METHOD = INVOKERHELPER_TYPE.getMethod("getProperty", new Parameter[]{new Parameter(OBJECT_TYPE, "object"), new Parameter(STRING_TYPE, "propertyName")});
-    private static final MethodNode INVOKERHELPER_GETPROPERTYSAFE_METHOD = INVOKERHELPER_TYPE.getMethod("getPropertySafe", new Parameter[]{new Parameter(OBJECT_TYPE, "object"), new Parameter(STRING_TYPE, "propertyName")});
-    private static final MethodNode CLOSURE_GETTHISOBJECT_METHOD = CLOSURE_TYPE.getMethod("getThisObject", Parameter.EMPTY_ARRAY);
     private static final ClassNode COLLECTION_TYPE = make(Collection.class);
+    private static final ClassNode INVOKERHELPER_TYPE = make(InvokerHelper.class);
     private static final MethodNode COLLECTION_SIZE_METHOD = COLLECTION_TYPE.getMethod("size", Parameter.EMPTY_ARRAY);
-    private static final MethodNode MAP_GET_METHOD = MAP_TYPE.getMethod("get", new Parameter[] { new Parameter(OBJECT_TYPE, "key")});
-
+    private static final MethodNode CLOSURE_GETTHISOBJECT_METHOD = CLOSURE_TYPE.getMethod("getThisObject", Parameter.EMPTY_ARRAY);
+    private static final MethodNode MAP_GET_METHOD = MAP_TYPE.getMethod("get", new Parameter[] {new Parameter(OBJECT_TYPE, "key")});
+    private static final MethodNode GROOVYOBJECT_GETPROPERTY_METHOD = GROOVY_OBJECT_TYPE.getMethod("getProperty", new Parameter[] {new Parameter(STRING_TYPE, "propertyName")});
+    private static final MethodNode INVOKERHELPER_GETPROPERTY_METHOD = INVOKERHELPER_TYPE.getMethod("getProperty", new Parameter[] {new Parameter(OBJECT_TYPE, "object"), new Parameter(STRING_TYPE, "propertyName")});
+    private static final MethodNode INVOKERHELPER_GETPROPERTYSAFE_METHOD = INVOKERHELPER_TYPE.getMethod("getPropertySafe", new Parameter[] {new Parameter(OBJECT_TYPE, "object"), new Parameter(STRING_TYPE, "propertyName")});
 
     private final StaticTypesWriterController controller;
 
@@ -192,16 +191,16 @@ public class StaticTypesCallSiteWriter extends CallSiteWriter implements Opcodes
             return;
         }
         if (makeGetPropertyWithGetter(receiver, receiverType, methodName, safe, implicitThis)) return;
-        if (makeGetField(receiver, receiverType, methodName, safe, implicitThis, samePackages(receiverType.getPackageName(), classNode.getPackageName()))) return;
+        if (makeGetField(receiver, receiverType, methodName, safe, implicitThis)) return;
         if (receiver instanceof ClassExpression) {
-            if (makeGetField(receiver, receiver.getType(), methodName, safe, implicitThis, samePackages(receiver.getType().getPackageName(), classNode.getPackageName()))) return;
+            if (makeGetField(receiver, receiver.getType(), methodName, safe, implicitThis)) return;
             if (makeGetPropertyWithGetter(receiver, receiver.getType(), methodName, safe, implicitThis)) return;
             if (makeGetPrivateFieldWithBridgeMethod(receiver, receiver.getType(), methodName, safe, implicitThis)) return;
         }
         if (isClassReceiver) {
             // we are probably looking for a property of the class
             if (makeGetPropertyWithGetter(receiver, CLASS_Type, methodName, safe, implicitThis)) return;
-            if (makeGetField(receiver, CLASS_Type, methodName, safe, false, true)) return;
+            if (makeGetField(receiver, CLASS_Type, methodName, safe, false)) return;
         }
         if (makeGetPrivateFieldWithBridgeMethod(receiver, receiverType, methodName, safe, implicitThis)) return;
 
@@ -480,7 +479,7 @@ public class StaticTypesCallSiteWriter extends CallSiteWriter implements Opcodes
 
         if (makeGetPropertyWithGetter(receiver, receiverType, property, safe, implicitThis)) return;
         if (makeGetPrivateFieldWithBridgeMethod(receiver, receiverType, property, safe, implicitThis)) return;
-        if (makeGetField(receiver, receiverType, property, safe, implicitThis, samePackages(receiverType.getPackageName(), classNode.getPackageName()))) return;
+        if (makeGetField(receiver, receiverType, property, safe, implicitThis)) return;
 
         MethodCallExpression call = new MethodCallExpression(
                 receiver,
@@ -565,12 +564,11 @@ public class StaticTypesCallSiteWriter extends CallSiteWriter implements Opcodes
         return false;
     }
 
-    boolean makeGetField(final Expression receiver, final ClassNode receiverType, final String fieldName, final boolean safe, final boolean implicitThis, final boolean samePackage) {
+    boolean makeGetField(final Expression receiver, final ClassNode receiverType, final String fieldName, final boolean safe, final boolean implicitThis) {
         FieldNode field = receiverType.getField(fieldName);
         // direct access is allowed if we are in the same class as the declaring class
         // or we are in an inner class
-        if (field !=null 
-                && isDirectAccessAllowed(field, controller.getClassNode(), samePackage)) {
+        if (field != null && isDirectAccessAllowed(field, controller.getClassNode())) {
             CompileStack compileStack = controller.getCompileStack();
             MethodVisitor mv = controller.getMethodVisitor();
             ClassNode replacementType = field.getOriginType();
@@ -613,19 +611,19 @@ public class StaticTypesCallSiteWriter extends CallSiteWriter implements Opcodes
 
         for (ClassNode intf : receiverType.getInterfaces()) {
             // GROOVY-7039
-            if (intf!=receiverType && makeGetField(receiver, intf, fieldName, safe, implicitThis, false)) {
+            if (intf != receiverType && makeGetField(receiver, intf, fieldName, safe, implicitThis)) {
                 return true;
             }
         }
 
         ClassNode superClass = receiverType.getSuperClass();
-        if (superClass !=null) {
-            return makeGetField(receiver, superClass, fieldName, safe, implicitThis, false);
+        if (superClass != null) {
+            return makeGetField(receiver, superClass, fieldName, safe, implicitThis);
         }
         return false;
     }
 
-    private static boolean isDirectAccessAllowed(FieldNode field, ClassNode receiver, boolean isSamePackage) {
+    private static boolean isDirectAccessAllowed(FieldNode field, ClassNode receiver) {
         ClassNode declaringClass = field.getDeclaringClass().redirect();
         ClassNode receiverType = receiver.redirect();
 
@@ -642,8 +640,8 @@ public class StaticTypesCallSiteWriter extends CallSiteWriter implements Opcodes
             receiverType = receiverType.getOuterClass();
         }
 
-        // finally public and inherited
-        return field.isPublic() || isSamePackage;
+        // finally public and visible
+        return field.isPublic() || samePackages(receiver.getPackageName(), declaringClass.getPackageName());
     }
 
     @Override
@@ -919,13 +917,12 @@ public class StaticTypesCallSiteWriter extends CallSiteWriter implements Opcodes
     }
 
     private boolean getField(PropertyExpression expression, Expression receiver, ClassNode receiverType, String name) {
-        ClassNode classNode = controller.getClassNode();
         boolean safe = expression.isSafe();
         boolean implicitThis = expression.isImplicitThis();
 
-        if (makeGetField(receiver, receiverType, name, safe, implicitThis, samePackages(receiverType.getPackageName(), classNode.getPackageName()))) return true;
+        if (makeGetField(receiver, receiverType, name, safe, implicitThis)) return true;
         if (receiver instanceof ClassExpression) {
-            if (makeGetField(receiver, receiver.getType(), name, safe, implicitThis, samePackages(receiver.getType().getPackageName(), classNode.getPackageName()))) return true;
+            if (makeGetField(receiver, receiver.getType(), name, safe, implicitThis)) return true;
             if (makeGetPrivateFieldWithBridgeMethod(receiver, receiver.getType(), name, safe, implicitThis)) return true;
         }
         if (makeGetPrivateFieldWithBridgeMethod(receiver, receiverType, name, safe, implicitThis)) return true;
@@ -935,7 +932,7 @@ public class StaticTypesCallSiteWriter extends CallSiteWriter implements Opcodes
             isClassReceiver = true;
             receiverType = receiverType.getGenericsTypes()[0].getType();
         }
-        if (isClassReceiver && makeGetField(receiver, CLASS_Type, name, safe, false, true)) return true;
+        if (isClassReceiver && makeGetField(receiver, CLASS_Type, name, safe, false)) return true;
         if (receiverType.isEnum()) {
             controller.getMethodVisitor().visitFieldInsn(GETSTATIC, BytecodeHelper.getClassInternalName(receiverType), name, BytecodeHelper.getTypeDescription(receiverType));
             controller.getOperandStack().push(receiverType);
diff --git a/src/test/org/codehaus/groovy/transform/packageScope/DifferentPackageTest.groovy b/src/test/org/codehaus/groovy/transform/packageScope/DifferentPackageTest.groovy
index a041e6a..408955c 100644
--- a/src/test/org/codehaus/groovy/transform/packageScope/DifferentPackageTest.groovy
+++ b/src/test/org/codehaus/groovy/transform/packageScope/DifferentPackageTest.groovy
@@ -18,10 +18,14 @@
  */
 package org.codehaus.groovy.transform.packageScope
 
+import groovy.transform.NotYetImplemented
 import org.codehaus.groovy.control.*
 import org.codehaus.groovy.tools.GroovyClass
+import org.junit.Test
 
-final class DifferentPackageTest extends GroovyTestCase {
+import static groovy.test.GroovyAssert.shouldFail
+
+final class DifferentPackageTest {
 
     /** Class in package {@code p} with package-private fields {@code value} and {@code CONST}. */
     private static final String P_DOT_ONE = '''
@@ -50,6 +54,7 @@ final class DifferentPackageTest extends GroovyTestCase {
 
     //--------------------------------------------------------------------------
 
+    @Test
     void testSamePackageShouldSeeInstanceProps1() {
         def loader = addSources(
             One: P_DOT_ONE,
@@ -67,6 +72,7 @@ final class DifferentPackageTest extends GroovyTestCase {
         assert loader.loadClass('p.Two').newInstance().valueSize() == 5
     }
 
+    @Test
     void testSamePackageShouldSeeInstanceProps2() {
         def loader = addSources(
             One: P_DOT_ONE,
@@ -84,6 +90,7 @@ final class DifferentPackageTest extends GroovyTestCase {
         assert loader.loadClass('p.Peer').newInstance().valueSize() == 5
     }
 
+    @Test
     void testSamePackageShouldSeeStaticProps1() {
         def loader = addSources(
             One: P_DOT_ONE,
@@ -101,6 +108,7 @@ final class DifferentPackageTest extends GroovyTestCase {
         assert loader.loadClass('p.Two').half() == 21
     }
 
+    @Test
     void testSamePackageShouldSeeStaticProps2() {
         def loader = addSources(
             One: P_DOT_ONE,
@@ -118,6 +126,7 @@ final class DifferentPackageTest extends GroovyTestCase {
         assert loader.loadClass('p.Two').newInstance().half() == 21
     }
 
+    @Test
     void testSamePackageShouldSeeStaticProps3() {
         def loader = addSources(
             One: P_DOT_ONE,
@@ -135,6 +144,7 @@ final class DifferentPackageTest extends GroovyTestCase {
         assert loader.loadClass('p.Peer').half() == 21
     }
 
+    @Test
     void testSamePackageShouldSeeStaticProps4() {
         def loader = addSources(
             One: P_DOT_ONE,
@@ -152,8 +162,8 @@ final class DifferentPackageTest extends GroovyTestCase {
         assert loader.loadClass('p.Peer').newInstance().half() == 21
     }
 
-    // GROOVY-9106
-    void _FIXME_testSamePackageShouldSeeStaticProps5() {
+    @Test // GROOVY-9106
+    void testSamePackageShouldSeeStaticProps5() {
         def loader = addSources(
             One: P_DOT_ONE,
             Two: '''
@@ -163,7 +173,7 @@ final class DifferentPackageTest extends GroovyTestCase {
                 class Two extends p.One {
                 }
             ''',
-            Peer: '''\
+            Peer: '''
                 package p
 
                 @groovy.transform.CompileStatic
@@ -177,8 +187,8 @@ final class DifferentPackageTest extends GroovyTestCase {
         assert loader.loadClass('p.Peer').half() == 21
     }
 
-    // GROOVY-9093
-    void _FIXME_testDifferentPackageShouldNotSeeInstanceProps() {
+    @Test @NotYetImplemented // GROOVY-9093
+    void testDifferentPackageShouldNotSeeInstanceProps() {
         def err = shouldFail CompilationFailedException, {
             def loader = addSources(
                 One: P_DOT_ONE,
@@ -199,8 +209,8 @@ final class DifferentPackageTest extends GroovyTestCase {
         assert err =~ / Access to ... value is forbidden /
     }
 
-    // GROOVY-9093
-    void _FIXME_testDifferentPackageShouldNotSeeStaticProps1() {
+    @Test @NotYetImplemented // GROOVY-9093
+    void testDifferentPackageShouldNotSeeStaticProps1() {
         def err = shouldFail CompilationFailedException, {
             def loader = addSources(
                 One: P_DOT_ONE,
@@ -221,6 +231,7 @@ final class DifferentPackageTest extends GroovyTestCase {
         assert err =~ / Access to p.One#CONST is forbidden /
     }
 
+    @Test
     void testDifferentPackageShouldNotSeeStaticProps2() {
         def err = shouldFail CompilationFailedException, {
             addSources(


[groovy] 01/05: GROOVY-9288, GROOVY-9292: add test cases

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

paulk pushed a commit to branch GROOVY_2_5_X
in repository https://gitbox.apache.org/repos/asf/groovy.git

commit 59289f00ce13be5bc339cd396ee795d34d2930ec
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Mon Oct 28 10:29:43 2019 -0500

    GROOVY-9288, GROOVY-9292: add test cases
---
 src/test/groovy/bugs/Groovy9288.groovy | 307 +++++++++++++++++++++++++++++++++
 1 file changed, 307 insertions(+)

diff --git a/src/test/groovy/bugs/Groovy9288.groovy b/src/test/groovy/bugs/Groovy9288.groovy
new file mode 100644
index 0000000..a09af73
--- /dev/null
+++ b/src/test/groovy/bugs/Groovy9288.groovy
@@ -0,0 +1,307 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package groovy.bugs
+
+import groovy.test.NotYetImplemented
+import org.junit.Test
+
+final class Groovy9288 {
+
+    private final GroovyShell shell = new GroovyShell()
+
+    @Test
+    void 'test accessing a protected super class field inside a closure - same package'() {
+        shell.with {
+            evaluate '''
+                package a
+
+                class A {
+                    protected String superField = 'works'
+                }
+
+                class B extends A {
+                    @groovy.transform.CompileStatic
+                    def test() {
+                        'something'.with {
+                            return superField
+                        }
+                    }
+                }
+
+                def obj = new B()
+                assert obj.test() == "works"
+            '''
+        }
+    }
+
+    @Test
+    void 'test accessing a protected super class field inside a closure - diff package'() {
+        shell.with {
+            evaluate '''
+                package a
+
+                class A {
+                    protected String superField = 'works'
+                }
+
+                assert true
+            '''
+
+            evaluate '''
+                package b
+
+                class B extends a.A {
+                    @groovy.transform.CompileStatic
+                    def test() {
+                        'something'.with {
+                            return superField
+                        }
+                    }
+                }
+
+                def obj = new B()
+                assert obj.test() == "works"
+            '''
+        }
+    }
+
+    @Test
+    void 'test accessing a protected super class field inside a closure - same package, this qualifier'() {
+        shell.with {
+            evaluate '''
+                package a
+
+                class A {
+                    protected String superField = 'works'
+                }
+
+                class B extends A {
+                    @groovy.transform.CompileStatic
+                    def test() {
+                        'something'.with {
+                            return this.superField
+                        }
+                    }
+                }
+
+                def obj = new B()
+                assert obj.test() == "works"
+            '''
+        }
+    }
+
+    @Test
+    void 'test accessing a protected super class field inside a closure - diff package, this qualifier'() {
+        shell.with {
+            evaluate '''
+                package a
+
+                class A {
+                    protected String superField = 'works'
+                }
+
+                assert true
+            '''
+
+            evaluate '''
+                package b
+
+                class B extends a.A {
+                    @groovy.transform.CompileStatic
+                    def test() {
+                        'something'.with {
+                            return this.superField
+                        }
+                    }
+                }
+
+                def obj = new B()
+                assert obj.test() == "works"
+            '''
+        }
+    }
+
+    @Test
+    void 'test accessing a protected super class field inside a closure - same package, owner qualifier'() {
+        shell.with {
+            evaluate '''
+                package a
+
+                class A {
+                    protected String superField = 'works'
+                }
+
+                class B extends A {
+                    @groovy.transform.CompileStatic
+                    def test() {
+                        'something'.with {
+                            return owner.superField
+                        }
+                    }
+                }
+
+                def obj = new B()
+                assert obj.test() == "works"
+            '''
+        }
+    }
+
+    @Test @NotYetImplemented // GROOVY-9292
+    void 'test accessing a protected super class field inside a closure - diff package, owner qualifier'() {
+        shell.with {
+            evaluate '''
+                package a
+
+                class A {
+                    protected String superField = 'works'
+                }
+
+                assert true
+            '''
+
+            evaluate '''
+                package b
+
+                class B extends a.A {
+                    @groovy.transform.CompileStatic
+                    def test() {
+                        'something'.with {
+                            return owner.superField
+                        }
+                    }
+                }
+
+                def obj = new B()
+                assert obj.test() == "works"
+            '''
+        }
+    }
+
+    @Test
+    void 'test accessing a protected super class field inside a closure - same package, delegate qualifier'() {
+        shell.with {
+            evaluate '''
+                package a
+
+                class A {
+                    protected String superField = 'works'
+                }
+
+                class B extends A {
+                    @groovy.transform.CompileStatic
+                    def test() {
+                        with {
+                            return delegate.superField
+                        }
+                    }
+                }
+
+                def obj = new B()
+                assert obj.test() == "works"
+            '''
+        }
+    }
+
+    @Test @NotYetImplemented // GROOVY-9292
+    void 'test accessing a protected super class field inside a closure - diff package, delegate qualifier'() {
+        shell.with {
+            evaluate '''
+                package a
+
+                class A {
+                    protected String superField = 'works'
+                }
+
+                assert true
+            '''
+
+            evaluate '''
+                package b
+
+                class B extends a.A {
+                    @groovy.transform.CompileStatic
+                    def test() {
+                        with {
+                            return delegate.superField
+                        }
+                    }
+                }
+
+                def obj = new B()
+                assert obj.test() == "works"
+            '''
+        }
+    }
+
+    @Test
+    void 'test accessing a protected super class field inside a closure - same package, thisObject qualifier'() {
+        shell.with {
+            evaluate '''
+                package a
+
+                class A {
+                    protected String superField = 'works'
+                }
+
+                class B extends A {
+                    @groovy.transform.CompileStatic
+                    def test() {
+                        'something'.with {
+                            return thisObject.superField
+                        }
+                    }
+                }
+
+                def obj = new B()
+                assert obj.test() == "works"
+            '''
+        }
+    }
+
+    @Test @NotYetImplemented // GROOVY-9292
+    void 'test accessing a protected super class field inside a closure - diff package, thisObject qualifier'() {
+        shell.with {
+            evaluate '''
+                package a
+
+                class A {
+                    protected String superField = 'works'
+                }
+
+                assert true
+            '''
+
+            evaluate '''
+                package b
+
+                class B extends a.A {
+                    @groovy.transform.CompileStatic
+                    def test() {
+                        'something'.with {
+                            return thisObject.superField
+                        }
+                    }
+                }
+
+                def obj = new B()
+                assert obj.test() == "works"
+            '''
+        }
+    }
+}