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 03:52:36 UTC
[groovy] branch GROOVY_2_5_X updated: GROOVY-9292: Compilation
error when accessing a protected super class field from a closure using
owner, delegate or thisObject qualifier (different package) (port to 2_5_X)
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
The following commit(s) were added to refs/heads/GROOVY_2_5_X by this push:
new baf08da GROOVY-9292: Compilation error when accessing a protected super class field from a closure using owner, delegate or thisObject qualifier (different package) (port to 2_5_X)
baf08da is described below
commit baf08da8b1619289af097b9060c05045210c87e2
Author: Daniel.Sun <re...@hotmail.com>
AuthorDate: Tue Oct 29 08:10:51 2019 +0800
GROOVY-9292: Compilation error when accessing a protected super class field from a closure using owner, delegate or thisObject qualifier (different package) (port to 2_5_X)
---
.../transform/stc/StaticTypeCheckingVisitor.java | 36 +-
src/test/groovy/bugs/Groovy9288.groovy | 9 +-
src/test/groovy/bugs/Groovy9292Bug.groovy | 1008 ++++++++++++++++++++
src/test/groovy/bugs/Groovy9293.groovy | 9 +-
4 files changed, 1051 insertions(+), 11 deletions(-)
diff --git a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
index 2e5ba41..5e83bc9 100644
--- a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
+++ b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
@@ -123,6 +123,7 @@ import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
+import java.util.Objects;
import java.util.Set;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.AtomicReference;
@@ -193,6 +194,7 @@ import static org.codehaus.groovy.ast.tools.WideningCategories.isLongCategory;
import static org.codehaus.groovy.ast.tools.WideningCategories.isNumberCategory;
import static org.codehaus.groovy.ast.tools.WideningCategories.lowestUpperBound;
import static org.codehaus.groovy.classgen.AsmClassGenerator.MINIMUM_BYTECODE_VERSION;
+import static org.codehaus.groovy.classgen.AsmClassGenerator.isNullConstant;
import static org.codehaus.groovy.runtime.DefaultGroovyMethods.asBoolean;
import static org.codehaus.groovy.syntax.Types.ASSIGN;
import static org.codehaus.groovy.syntax.Types.ASSIGNMENT_OPERATOR;
@@ -213,6 +215,7 @@ import static org.codehaus.groovy.syntax.Types.MINUS_MINUS;
import static org.codehaus.groovy.syntax.Types.MOD;
import static org.codehaus.groovy.syntax.Types.MOD_EQUAL;
import static org.codehaus.groovy.syntax.Types.PLUS_PLUS;
+import static org.codehaus.groovy.transform.sc.StaticCompilationMetadataKeys.RECEIVER_OF_DYNAMIC_PROPERTY;
import static org.codehaus.groovy.transform.stc.StaticTypeCheckingSupport.ArrayList_TYPE;
import static org.codehaus.groovy.transform.stc.StaticTypeCheckingSupport.Collection_TYPE;
import static org.codehaus.groovy.transform.stc.StaticTypeCheckingSupport.Matcher_TYPE;
@@ -1403,6 +1406,9 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport {
return existsProperty(pexp, checkForReadOnly, null);
}
+ private static final Set<String> CLOSURE_IMPLICIT_VARIABLE_SET =
+ Collections.unmodifiableSet(new HashSet<>(Arrays.asList("it", "this", "thisObject", "owner", "delegate")));
+
/**
* Checks whether a property exists on the receiver, or on any of the possible receiver classes (found in the
* temporary type information table)
@@ -1486,8 +1492,20 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport {
FieldNode field = current.getDeclaredField(propertyName);
field = allowStaticAccessToMember(field, staticOnly);
- if (storeField(field, isAttributeExpression, pexp, current, visitor, receiver.getData(), !readMode))
+
+ if (null != field) {
+ int fieldModifiers = field.getModifiers();
+ if (Modifier.isProtected(fieldModifiers) || isPackagePrivate(fieldModifiers)) {
+ if (null != typeCheckingContext.getEnclosingClosure() && CLOSURE_IMPLICIT_VARIABLE_SET.contains(objectExpression.getText())) {
+ objectExpression.putNodeMetaData(RECEIVER_OF_DYNAMIC_PROPERTY, OBJECT_TYPE);
+ }
+ }
+ }
+
+ if (storeField(field, isAttributeExpression, pexp, current, visitor, receiver.getData(), !readMode)) {
+ pexp.removeNodeMetaData(READONLY_PROPERTY);
return true;
+ }
boolean isThisExpression = objectExpression instanceof VariableExpression
&& ((VariableExpression) objectExpression).isThisExpression()
@@ -1630,6 +1648,22 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport {
return foundGetterOrSetter;
}
+ private static boolean isPackagePrivate(int modifiers) {
+ return !(Modifier.isPublic(modifiers) || Modifier.isProtected(modifiers) || Modifier.isPrivate(modifiers));
+ }
+
+ private static boolean hasAccessToField(FieldNode field, ClassNode objectExpressionType) {
+ if (field != null) {
+ if (field.isPublic() || field.isProtected()) {
+ return true;
+ }
+ if (!field.isPrivate() && Objects.equals(objectExpressionType.getPackageName(), field.getDeclaringClass().getPackageName())) {
+ return true;
+ }
+ }
+ return false;
+ }
+
private MethodNode findGetter(ClassNode current, String name, boolean searchOuterClasses) {
MethodNode getterMethod = current.getGetterMethod(name);
if (getterMethod == null && searchOuterClasses && current instanceof InnerClassNode) {
diff --git a/src/test/groovy/bugs/Groovy9288.groovy b/src/test/groovy/bugs/Groovy9288.groovy
index c09dda0..d8650ee 100644
--- a/src/test/groovy/bugs/Groovy9288.groovy
+++ b/src/test/groovy/bugs/Groovy9288.groovy
@@ -18,7 +18,6 @@
*/
package groovy.bugs
-import groovy.transform.NotYetImplemented
import org.junit.Test
final class Groovy9288 {
@@ -100,7 +99,7 @@ final class Groovy9288 {
'''
}
- @Test @NotYetImplemented // GROOVY-9292
+ @Test
void 'test accessing a protected super class field inside a closure - diff package, it qualifier'() {
shell.evaluate '''
package a
@@ -204,7 +203,7 @@ final class Groovy9288 {
'''
}
- @Test @NotYetImplemented // GROOVY-9292
+ @Test
void 'test accessing a protected super class field inside a closure - diff package, owner qualifier'() {
shell.evaluate '''
package a
@@ -256,7 +255,7 @@ final class Groovy9288 {
'''
}
- @Test @NotYetImplemented // GROOVY-9292
+ @Test
void 'test accessing a protected super class field inside a closure - diff package, delegate qualifier'() {
shell.evaluate '''
package a
@@ -308,7 +307,7 @@ final class Groovy9288 {
'''
}
- @Test @NotYetImplemented // GROOVY-9292
+ @Test
void 'test accessing a protected super class field inside a closure - diff package, thisObject qualifier'() {
shell.evaluate '''
package a
diff --git a/src/test/groovy/bugs/Groovy9292Bug.groovy b/src/test/groovy/bugs/Groovy9292Bug.groovy
new file mode 100644
index 0000000..58ccc25
--- /dev/null
+++ b/src/test/groovy/bugs/Groovy9292Bug.groovy
@@ -0,0 +1,1008 @@
+/*
+ * 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.transform.NotYetImplemented
+import org.junit.Test
+
+final class Groovy9292Bug {
+
+ @Test
+ void "test accessing a protected super class field from inside a closure - different package"() {
+ GroovyShell shell = new GroovyShell()
+ shell.evaluate('''
+ package a
+
+ import groovy.transform.CompileStatic
+
+ @CompileStatic
+ abstract class Abstract_Class {
+ protected String superField = 'field'
+
+ abstract String doThing()
+ }
+ assert true
+ ''')
+
+ shell.evaluate('''
+ package b
+
+ import a.Abstract_Class
+ import groovy.transform.CompileStatic
+
+ @CompileStatic
+ class ConcreteClass extends Abstract_Class {
+
+ @Override
+ String doThing() {
+ 'something'.with {
+ return superField
+ }
+ }
+ }
+ assert true
+ ''')
+
+ shell.evaluate("assert new b.ConcreteClass().doThing() == 'field'")
+ }
+
+ @Test
+ void "test accessing a protected super class field from inside a closure - same package"() {
+ GroovyShell shell = new GroovyShell()
+ shell.evaluate('''
+ package a
+
+ import groovy.transform.CompileStatic
+
+ @CompileStatic
+ abstract class Abstract_Class {
+ protected String superField = 'field'
+
+ abstract String doThing()
+ }
+ assert true
+ ''')
+
+ shell.evaluate('''
+ package a
+
+ import a.Abstract_Class
+ import groovy.transform.CompileStatic
+
+ @CompileStatic
+ class ConcreteClass extends Abstract_Class {
+
+ @Override
+ String doThing() {
+ 'something'.with {
+ return superField
+ }
+ }
+ }
+ assert true
+ ''')
+
+ shell.evaluate("assert new a.ConcreteClass().doThing() == 'field'")
+ }
+
+
+ @Test
+ void "test accessing a protected super class field from inside a closure - using it - different package"() {
+ GroovyShell shell = new GroovyShell()
+ shell.evaluate('''
+ package a
+
+ import groovy.transform.CompileStatic
+
+ @CompileStatic
+ abstract class Abstract_Class {
+ protected String superField = 'field'
+
+ abstract String doThing()
+ }
+ assert true
+ ''')
+
+ shell.evaluate('''
+ package b
+
+ import a.Abstract_Class
+ import groovy.transform.CompileStatic
+
+ @CompileStatic
+ class ConcreteClass extends Abstract_Class {
+
+ @Override
+ String doThing() {
+ this.with {
+ return it.superField
+ }
+ }
+ }
+ assert true
+ ''')
+
+ shell.evaluate("assert new b.ConcreteClass().doThing() == 'field'")
+ }
+
+ @Test
+ void "test accessing a protected super class field from inside a closure - using this - different package"() {
+ GroovyShell shell = new GroovyShell()
+ shell.evaluate('''
+ package a
+
+ import groovy.transform.CompileStatic
+
+ @CompileStatic
+ abstract class Abstract_Class {
+ protected String superField = 'field'
+
+ abstract String doThing()
+ }
+ assert true
+ ''')
+
+ shell.evaluate('''
+ package b
+
+ import a.Abstract_Class
+ import groovy.transform.CompileStatic
+
+ @CompileStatic
+ class ConcreteClass extends Abstract_Class {
+
+ @Override
+ String doThing() {
+ 'something'.with {
+ return this.superField
+ }
+ }
+ }
+ assert true
+ ''')
+
+ shell.evaluate("assert new b.ConcreteClass().doThing() == 'field'")
+ }
+
+
+ @Test
+ void "test accessing a protected super class field from inside a closure - using thisObject - different package"() {
+ GroovyShell shell = new GroovyShell()
+ shell.evaluate('''
+ package a
+
+ import groovy.transform.CompileStatic
+
+ @CompileStatic
+ abstract class Abstract_Class {
+ protected String superField = 'field'
+
+ abstract String doThing()
+ }
+ assert true
+ ''')
+
+ shell.evaluate('''
+ package b
+
+ import a.Abstract_Class
+ import groovy.transform.CompileStatic
+
+ @CompileStatic
+ class ConcreteClass extends Abstract_Class {
+
+ @Override
+ String doThing() {
+ 'something'.with {
+ return thisObject.superField
+ }
+ }
+ }
+ assert true
+ ''')
+
+ shell.evaluate("assert new b.ConcreteClass().doThing() == 'field'")
+ }
+
+ @Test
+ void "test accessing a protected super class field from inside a closure - using owner - different package"() {
+ GroovyShell shell = new GroovyShell()
+ shell.evaluate('''
+ package a
+
+ import groovy.transform.CompileStatic
+
+ @CompileStatic
+ abstract class Abstract_Class {
+ protected String superField = 'field'
+
+ abstract String doThing()
+ }
+ assert true
+ ''')
+
+ shell.evaluate('''
+ package b
+
+ import a.Abstract_Class
+ import groovy.transform.CompileStatic
+
+ @CompileStatic
+ class ConcreteClass extends Abstract_Class {
+
+ @Override
+ String doThing() {
+ 'something'.with {
+ return owner.superField
+ }
+ }
+ }
+ assert true
+ ''')
+
+ shell.evaluate("assert new b.ConcreteClass().doThing() == 'field'")
+ }
+
+ @Test
+ void "test accessing a protected super class field from inside a closure - using delegate - different package"() {
+ GroovyShell shell = new GroovyShell()
+ shell.evaluate('''
+ package a
+
+ import groovy.transform.CompileStatic
+
+ @CompileStatic
+ abstract class Abstract_Class {
+ protected String superField = 'field'
+
+ abstract String doThing()
+ }
+ assert true
+ ''')
+
+ shell.evaluate('''
+ package b
+
+ import a.Abstract_Class
+ import groovy.transform.CompileStatic
+
+ @CompileStatic
+ class ConcreteClass extends Abstract_Class {
+
+ @Override
+ String doThing() {
+ this.with {
+ return delegate.superField
+ }
+ }
+ }
+ assert true
+ ''')
+
+ shell.evaluate("assert new b.ConcreteClass().doThing() == 'field'")
+ }
+
+ @Test
+ void "test accessing a package-private super class field from inside a closure - same package"() {
+ GroovyShell shell = new GroovyShell()
+ shell.evaluate('''
+ package a
+
+ import groovy.transform.CompileStatic
+
+ @CompileStatic
+ abstract class Abstract_Class {
+ @groovy.transform.PackageScope String superField = 'field'
+
+ abstract String doThing()
+ }
+ assert true
+ ''')
+
+ shell.evaluate('''
+ package a
+
+ import a.Abstract_Class
+ import groovy.transform.CompileStatic
+
+ @CompileStatic
+ class ConcreteClass extends Abstract_Class {
+
+ @Override
+ String doThing() {
+ this.with {
+ return delegate.superField
+ }
+ }
+ }
+ assert true
+ ''')
+
+ shell.evaluate("assert new a.ConcreteClass().doThing() == 'field'")
+ }
+
+ @Test
+ void "test accessing a package-private super class field from inside a closure - using delegate - same package"() {
+ GroovyShell shell = new GroovyShell()
+ shell.evaluate('''
+ package a
+
+ import groovy.transform.CompileStatic
+
+ @CompileStatic
+ abstract class Abstract_Class {
+ @groovy.transform.PackageScope String superField = 'field'
+
+ abstract String doThing()
+ }
+ assert true
+ ''')
+
+ shell.evaluate('''
+ package a
+
+ import a.Abstract_Class
+ import groovy.transform.CompileStatic
+
+ @CompileStatic
+ class ConcreteClass extends Abstract_Class {
+
+ @Override
+ String doThing() {
+ this.with {
+ return delegate.superField
+ }
+ }
+ }
+ assert true
+ ''')
+
+ shell.evaluate("assert new a.ConcreteClass().doThing() == 'field'")
+ }
+
+ @Test
+ void "test accessing a package-private super class field from inside a closure - using it - same package"() {
+ GroovyShell shell = new GroovyShell()
+ shell.evaluate('''
+ package a
+
+ import groovy.transform.CompileStatic
+
+ @CompileStatic
+ abstract class Abstract_Class {
+ @groovy.transform.PackageScope String superField = 'field'
+
+ abstract String doThing()
+ }
+ assert true
+ ''')
+
+ shell.evaluate('''
+ package a
+
+ import a.Abstract_Class
+ import groovy.transform.CompileStatic
+
+ @CompileStatic
+ class ConcreteClass extends Abstract_Class {
+
+ @Override
+ String doThing() {
+ this.with {
+ return it.superField
+ }
+ }
+ }
+ assert true
+ ''')
+
+ shell.evaluate("assert new a.ConcreteClass().doThing() == 'field'")
+ }
+
+ @NotYetImplemented // java.lang.IllegalAccessError: class a.ConcreteClass$_doThing_closure1 tried to access field a.Abstract_Class.superField (a.ConcreteClass$_doThing_closure1 is in unnamed module of loader groovy.lang.GroovyClassLoader$InnerLoader @5fa47fea; a.Abstract_Class is in unnamed module of loader groovy.lang.GroovyClassLoader$InnerLoader @28cda624)
+ @Test
+ void "test accessing a package-private super class field from inside a closure - using this - same package"() {
+ GroovyShell shell = new GroovyShell()
+ shell.evaluate('''
+ package a
+
+ import groovy.transform.CompileStatic
+
+ @CompileStatic
+ abstract class Abstract_Class {
+ @groovy.transform.PackageScope String superField = 'field'
+
+ abstract String doThing()
+ }
+ assert true
+ ''')
+
+ shell.evaluate('''
+ package a
+
+ import a.Abstract_Class
+ import groovy.transform.CompileStatic
+
+ @CompileStatic
+ class ConcreteClass extends Abstract_Class {
+
+ @Override
+ String doThing() {
+ this.with {
+ return this.superField
+ }
+ }
+ }
+ assert true
+ ''')
+
+ shell.evaluate("assert new a.ConcreteClass().doThing() == 'field'")
+ }
+
+ @Test
+ void "test accessing a package-private super class field from inside a closure - using thisObject - same package"() {
+ GroovyShell shell = new GroovyShell()
+ shell.evaluate('''
+ package a
+
+ import groovy.transform.CompileStatic
+
+ @CompileStatic
+ abstract class Abstract_Class {
+ @groovy.transform.PackageScope String superField = 'field'
+
+ abstract String doThing()
+ }
+ assert true
+ ''')
+
+ shell.evaluate('''
+ package a
+
+ import a.Abstract_Class
+ import groovy.transform.CompileStatic
+
+ @CompileStatic
+ class ConcreteClass extends Abstract_Class {
+
+ @Override
+ String doThing() {
+ this.with {
+ return thisObject.superField
+ }
+ }
+ }
+ assert true
+ ''')
+
+ shell.evaluate("assert new a.ConcreteClass().doThing() == 'field'")
+ }
+
+ @Test
+ void "test accessing a package-private super class field from inside a closure - using owner - same package"() {
+ GroovyShell shell = new GroovyShell()
+ shell.evaluate('''
+ package a
+
+ import groovy.transform.CompileStatic
+
+ @CompileStatic
+ abstract class Abstract_Class {
+ @groovy.transform.PackageScope String superField = 'field'
+
+ abstract String doThing()
+ }
+ assert true
+ ''')
+
+ shell.evaluate('''
+ package a
+
+ import a.Abstract_Class
+ import groovy.transform.CompileStatic
+
+ @CompileStatic
+ class ConcreteClass extends Abstract_Class {
+
+ @Override
+ String doThing() {
+ this.with {
+ return owner.superField
+ }
+ }
+ }
+ assert true
+ ''')
+
+ shell.evaluate("assert new a.ConcreteClass().doThing() == 'field'")
+ }
+
+
+ @Test
+ void "test accessing a public super class field from inside a closure - different package -- regression"() {
+ GroovyShell shell = new GroovyShell()
+ shell.evaluate('''
+ package a
+
+ import groovy.transform.CompileStatic
+
+ @CompileStatic
+ abstract class Abstract_Class {
+ public String superField = 'field'
+
+ abstract String doThing()
+ }
+ assert true
+ ''')
+
+ shell.evaluate('''
+ package b
+
+ import a.Abstract_Class
+ import groovy.transform.CompileStatic
+
+ @CompileStatic
+ class ConcreteClass extends Abstract_Class {
+
+ @Override
+ String doThing() {
+ this.with {
+ return superField
+ }
+ }
+ }
+ assert true
+ ''')
+
+ shell.evaluate("assert new b.ConcreteClass().doThing() == 'field'")
+ }
+
+ @Test
+ void "test accessing a public super class field from inside a closure - using delegate - different package"() {
+ GroovyShell shell = new GroovyShell()
+ shell.evaluate('''
+ package a
+
+ import groovy.transform.CompileStatic
+
+ @CompileStatic
+ abstract class Abstract_Class {
+ public String superField = 'field'
+
+ abstract String doThing()
+ }
+ assert true
+ ''')
+
+ shell.evaluate('''
+ package b
+
+ import a.Abstract_Class
+ import groovy.transform.CompileStatic
+
+ @CompileStatic
+ class ConcreteClass extends Abstract_Class {
+
+ @Override
+ String doThing() {
+ this.with {
+ return delegate.superField
+ }
+ }
+ }
+ assert true
+ ''')
+
+ shell.evaluate("assert new b.ConcreteClass().doThing() == 'field'")
+ }
+
+
+ @Test
+ void "test accessing a public super class field from inside a closure - using it - different package"() {
+ GroovyShell shell = new GroovyShell()
+ shell.evaluate('''
+ package a
+
+ import groovy.transform.CompileStatic
+
+ @CompileStatic
+ abstract class Abstract_Class {
+ public String superField = 'field'
+
+ abstract String doThing()
+ }
+ assert true
+ ''')
+
+ shell.evaluate('''
+ package b
+
+ import a.Abstract_Class
+ import groovy.transform.CompileStatic
+
+ @CompileStatic
+ class ConcreteClass extends Abstract_Class {
+
+ @Override
+ String doThing() {
+ this.with {
+ return it.superField
+ }
+ }
+ }
+ assert true
+ ''')
+
+ shell.evaluate("assert new b.ConcreteClass().doThing() == 'field'")
+ }
+
+ @Test
+ void "test accessing a public super class field from inside a closure - using this - different package"() {
+ GroovyShell shell = new GroovyShell()
+ shell.evaluate('''
+ package a
+
+ import groovy.transform.CompileStatic
+
+ @CompileStatic
+ abstract class Abstract_Class {
+ public String superField = 'field'
+
+ abstract String doThing()
+ }
+ assert true
+ ''')
+
+ shell.evaluate('''
+ package b
+
+ import a.Abstract_Class
+ import groovy.transform.CompileStatic
+
+ @CompileStatic
+ class ConcreteClass extends Abstract_Class {
+
+ @Override
+ String doThing() {
+ this.with {
+ return this.superField
+ }
+ }
+ }
+ assert true
+ ''')
+
+ shell.evaluate("assert new b.ConcreteClass().doThing() == 'field'")
+ }
+
+ @Test
+ void "test accessing a public super class field from inside a closure - using thisObject - different package"() {
+ GroovyShell shell = new GroovyShell()
+ shell.evaluate('''
+ package a
+
+ import groovy.transform.CompileStatic
+
+ @CompileStatic
+ abstract class Abstract_Class {
+ public String superField = 'field'
+
+ abstract String doThing()
+ }
+ assert true
+ ''')
+
+ shell.evaluate('''
+ package b
+
+ import a.Abstract_Class
+ import groovy.transform.CompileStatic
+
+ @CompileStatic
+ class ConcreteClass extends Abstract_Class {
+
+ @Override
+ String doThing() {
+ this.with {
+ return thisObject.superField
+ }
+ }
+ }
+ assert true
+ ''')
+
+ shell.evaluate("assert new b.ConcreteClass().doThing() == 'field'")
+ }
+
+ @Test
+ void "test accessing a public super class field from inside a closure - using owner - different package"() {
+ GroovyShell shell = new GroovyShell()
+ shell.evaluate('''
+ package a
+
+ import groovy.transform.CompileStatic
+
+ @CompileStatic
+ abstract class Abstract_Class {
+ public String superField = 'field'
+
+ abstract String doThing()
+ }
+ assert true
+ ''')
+
+ shell.evaluate('''
+ package b
+
+ import a.Abstract_Class
+ import groovy.transform.CompileStatic
+
+ @CompileStatic
+ class ConcreteClass extends Abstract_Class {
+
+ @Override
+ String doThing() {
+ this.with {
+ return owner.superField
+ }
+ }
+ }
+ assert true
+ ''')
+
+ shell.evaluate("assert new b.ConcreteClass().doThing() == 'field'")
+ }
+
+
+ @Test
+ void "test accessing a private super class field from inside a closure via getter - different package -- regression"() {
+ GroovyShell shell = new GroovyShell()
+ shell.evaluate('''
+ package a
+
+ import groovy.transform.CompileStatic
+
+ @CompileStatic
+ abstract class Abstract_Class {
+ String superField = 'field'
+
+ abstract String doThing()
+ }
+ assert true
+ ''')
+
+ shell.evaluate('''
+ package b
+
+ import a.Abstract_Class
+ import groovy.transform.CompileStatic
+
+ @CompileStatic
+ class ConcreteClass extends Abstract_Class {
+
+ @Override
+ String doThing() {
+ this.with {
+ return superField
+ }
+ }
+ }
+ assert true
+ ''')
+
+ shell.evaluate("assert new b.ConcreteClass().doThing() == 'field'")
+ }
+
+
+ @Test
+ void "test accessing a private super class field from inside a closure via getter - using delegate - different package -- regression"() {
+ GroovyShell shell = new GroovyShell()
+ shell.evaluate('''
+ package a
+
+ import groovy.transform.CompileStatic
+
+ @CompileStatic
+ abstract class Abstract_Class {
+ String superField = 'field'
+
+ abstract String doThing()
+ }
+ assert true
+ ''')
+
+ shell.evaluate('''
+ package b
+
+ import a.Abstract_Class
+ import groovy.transform.CompileStatic
+
+ @CompileStatic
+ class ConcreteClass extends Abstract_Class {
+
+ @Override
+ String doThing() {
+ this.with {
+ return delegate.superField
+ }
+ }
+ }
+ assert true
+ ''')
+
+ shell.evaluate("assert new b.ConcreteClass().doThing() == 'field'")
+ }
+
+ @Test
+ void "test accessing a private super class field from inside a closure via getter - using it - different package -- regression"() {
+ GroovyShell shell = new GroovyShell()
+ shell.evaluate('''
+ package a
+
+ import groovy.transform.CompileStatic
+
+ @CompileStatic
+ abstract class Abstract_Class {
+ String superField = 'field'
+
+ abstract String doThing()
+ }
+ assert true
+ ''')
+
+ shell.evaluate('''
+ package b
+
+ import a.Abstract_Class
+ import groovy.transform.CompileStatic
+
+ @CompileStatic
+ class ConcreteClass extends Abstract_Class {
+
+ @Override
+ String doThing() {
+ this.with {
+ return it.superField
+ }
+ }
+ }
+ assert true
+ ''')
+
+ shell.evaluate("assert new b.ConcreteClass().doThing() == 'field'")
+ }
+
+
+ @Test
+ void "test accessing a private super class field from inside a closure via getter - using this - different package -- regression"() {
+ GroovyShell shell = new GroovyShell()
+ shell.evaluate('''
+ package a
+
+ import groovy.transform.CompileStatic
+
+ @CompileStatic
+ abstract class Abstract_Class {
+ String superField = 'field'
+
+ abstract String doThing()
+ }
+ assert true
+ ''')
+
+ shell.evaluate('''
+ package b
+
+ import a.Abstract_Class
+ import groovy.transform.CompileStatic
+
+ @CompileStatic
+ class ConcreteClass extends Abstract_Class {
+
+ @Override
+ String doThing() {
+ this.with {
+ return this.superField
+ }
+ }
+ }
+ assert true
+ ''')
+
+ shell.evaluate("assert new b.ConcreteClass().doThing() == 'field'")
+ }
+
+ @Test
+ void "test accessing a private super class field from inside a closure via getter - using thisObject - different package -- regression"() {
+ GroovyShell shell = new GroovyShell()
+ shell.evaluate('''
+ package a
+
+ import groovy.transform.CompileStatic
+
+ @CompileStatic
+ abstract class Abstract_Class {
+ String superField = 'field'
+
+ abstract String doThing()
+ }
+ assert true
+ ''')
+
+ shell.evaluate('''
+ package b
+
+ import a.Abstract_Class
+ import groovy.transform.CompileStatic
+
+ @CompileStatic
+ class ConcreteClass extends Abstract_Class {
+
+ @Override
+ String doThing() {
+ this.with {
+ return thisObject.superField
+ }
+ }
+ }
+ assert true
+ ''')
+
+ shell.evaluate("assert new b.ConcreteClass().doThing() == 'field'")
+ }
+
+ @Test
+ void "test accessing a private super class field from inside a closure via getter - using owner - different package -- regression"() {
+ GroovyShell shell = new GroovyShell()
+ shell.evaluate('''
+ package a
+
+ import groovy.transform.CompileStatic
+
+ @CompileStatic
+ abstract class Abstract_Class {
+ String superField = 'field'
+
+ abstract String doThing()
+ }
+ assert true
+ ''')
+
+ shell.evaluate('''
+ package b
+
+ import a.Abstract_Class
+ import groovy.transform.CompileStatic
+
+ @CompileStatic
+ class ConcreteClass extends Abstract_Class {
+
+ @Override
+ String doThing() {
+ this.with {
+ return owner.superField
+ }
+ }
+ }
+ assert true
+ ''')
+
+ shell.evaluate("assert new b.ConcreteClass().doThing() == 'field'")
+ }
+}
diff --git a/src/test/groovy/bugs/Groovy9293.groovy b/src/test/groovy/bugs/Groovy9293.groovy
index 9e62c3c..5ba45b2 100644
--- a/src/test/groovy/bugs/Groovy9293.groovy
+++ b/src/test/groovy/bugs/Groovy9293.groovy
@@ -18,7 +18,6 @@
*/
package groovy.bugs
-import groovy.transform.NotYetImplemented
import org.junit.Test
import static groovy.test.GroovyAssert.shouldFail
@@ -106,7 +105,7 @@ final class Groovy9293 {
'''
}
- @Test @NotYetImplemented // GROOVY-9293
+ @Test
void 'test accessing a package-private super class field inside a closure - diff package, it qualifier'() {
shouldFail(MissingPropertyException) {
shell.evaluate '''
@@ -216,7 +215,7 @@ final class Groovy9293 {
'''
}
- @Test @NotYetImplemented // GROOVY-9293
+ @Test
void 'test accessing a package-private super class field inside a closure - diff package, owner qualifier'() {
shouldFail(MissingPropertyException) {
shell.evaluate '''
@@ -271,7 +270,7 @@ final class Groovy9293 {
'''
}
- @Test @NotYetImplemented // GROOVY-9293
+ @Test
void 'test accessing a package-private super class field inside a closure - diff package, delegate qualifier'() {
shouldFail(MissingPropertyException) {
shell.evaluate '''
@@ -326,7 +325,7 @@ final class Groovy9293 {
'''
}
- @Test @NotYetImplemented // GROOVY-9293
+ @Test
void 'test accessing a package-private super class field inside a closure - diff package, thisObject qualifier'() {
shouldFail(MissingPropertyException) {
shell.evaluate '''