[ https://issues.apache.org/jira/browse/GROOVY-9292?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Daniel Sun updated GROOVY-9292: ------------------------------- Description: Compilation fails when accessing a protected(via `thisObject`, `owner` and `delegate`)/package-private super class field from inside a closure: {code:java} GroovyShell shell = new GroovyShell() shell.evaluate(''' package a import groovy.transform.CompileStatic @CompileStatic abstract class Abstract_Class { protected String protectedField = 'field' // `@PackageScope` fails too 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.protectedField // `thisObject.protectedField`, `delegate.protectedField` fails too } } } assert true''') shell.evaluate("assert new b.ConcreteClass().doThing() == 'field'") {code} *Note:* accessing a package-private super class field from inside a closure via `this` still fails, we will open a new ticket to track it: {code:java} 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'") {code} was: Compilation fails when accessing a protected(via `thisObject`, `owner` and `delegate`)/package-private super class field from inside a closure: {code:java} GroovyShell shell = new GroovyShell() shell.evaluate(''' package a import groovy.transform.CompileStatic @CompileStatic abstract class Abstract_Class { protected String protectedField = 'field' // `@PackageScope` fails too 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.protectedField // `thisObject.protectedField`, `delegate.protectedField` fails too } } } assert true''') shell.evaluate("assert new b.ConcreteClass().doThing() == 'field'") {code} Note: accessing a package-private super class field from inside a closure via `this` still fails, we will open a new ticket to track it: {code:java} 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'") {code} > Compilation error when accessing a protected(via `thisObject`, `owner` and > `delegate`)/package-private super class field from inside a closure > ---------------------------------------------------------------------------------------------------------------------------------------------- > > Key: GROOVY-9292 > URL: https://issues.apache.org/jira/browse/GROOVY-9292 > Project: Groovy > Issue Type: Bug > Components: Static compilation > Affects Versions: 2.5.8, 3.0.0-rc-1 > Reporter: Daniel Sun > Assignee: Daniel Sun > Priority: Major > Fix For: 3.0.0-rc-2 > > > Compilation fails when accessing a protected(via `thisObject`, `owner` and > `delegate`)/package-private super class field from inside a closure: > {code:java} > GroovyShell shell = new GroovyShell() > shell.evaluate(''' > package a > > import groovy.transform.CompileStatic > > @CompileStatic > abstract class Abstract_Class { > protected String protectedField = 'field' // `@PackageScope` fails too > > 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.protectedField // `thisObject.protectedField`, > `delegate.protectedField` fails too > } > } > } > assert true''') > shell.evaluate("assert new b.ConcreteClass().doThing() == 'field'") > {code} > *Note:* accessing a package-private super class field from inside a closure > via `this` still fails, we will open a new ticket to track it: > {code:java} > 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'") > {code} -- This message was sent by Atlassian Jira (v8.3.4#803005)