Jason Garrett created GROOVY-11029:
--------------------------------------
Summary: CompileStatic: default-visible property is not accessible
by a subclass that defines a getter and setter
Key: GROOVY-11029
URL: https://issues.apache.org/jira/browse/GROOVY-11029
Project: Groovy
Issue Type: Bug
Components: Compiler, Static compilation
Affects Versions: 4.0.11
Reporter: Jason Garrett
If a class defines a default-visibility property and a subclass declares a
getter and a setter for that property, the subclass cannot access super's
property.
{code:java}
import groovy.transform.CompileStatic
import spock.lang.Specification
class Foo {
Object myThing // everything works if "public" is added
}
@CompileStatic // everything works without CompileStatic
class Bar extends Foo {
void setMyThing(Object list) {
super.myThing = list
}
Object getMyThing() {
return super.myThing as List // groovy.lang.MissingPropertyException:
No such property: myThing for class: Bar
// return super.@myThing as List // [Static type checking] - The field
Foo.myThing is not accessible
}
}
class BarTest extends Specification {
def "myThing"() {
when:
Bar bar = new Bar()
List list = []
bar.myThing = list
then:
bar.myThing.is(list)
}
}{code}
[Live
Demo|https://gwc-experiment.appspot.com/?g=groovy_4_0&codez=eJxtUkFugzAQPNevWOWUHkruSJGiVu2paSsltygHYzbgBmzLNiGoyt9rOw6BlpVAMrOenZ2B10pqC4WW8tQlVlNhDlLXyYusFa9wY6nljPBrl1GSHZOKiiLZKGT8wJmDpSCEVdQYeJMSfgi4-sy-kVmou23JRQGwWACeUHc2HFupjwb4AWaqySrOZsAN0DzHnFwIWY1mT99tuS1lY2Es86rimWrAs0WRDxWdJM_BoF1fJc2jwoob-xhbfJlGoU5uupcBD-AlvIfLFXeyIYNG22jxh4gaeHdMYZnodbBxzY1x-JeWrtt2r2eGyjuawod0FKwEFaG0N9PlA2HT1K9KHOPU5NXU6F301HYKgZXIjq5jD0-wLREOHKvcO9ardqkIaYEyhk5mVmF04kLuVm_Rcd_sHv0V0ZMcXc6RcTZyqi1RpP3Jl48uc88SBLb-NH_s8Yewhc_Dwbv9_bu7MBWYL_tvwqA54WYe4r9t9QtqK_c0]
--
This message was sent by Atlassian Jira
(v8.20.10#820010)