[ https://issues.apache.org/jira/browse/GROOVY-9851?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17745135#comment-17745135 ]
Eric Milles edited comment on GROOVY-9851 at 7/20/23 3:35 PM: -------------------------------------------------------------- Consistency is now quite good. The only subversive access that remains is acquiring a method closure for the parent class and binding {{this}} with curry. {code:groovy} @Test void 'testGROOVY 8999 9851'() { assertScript '''import static groovy.test.GroovyAssert.shouldFail class Foo { private String field = 'field' private String method() { 'method' } } class Bar extends Foo { void test1() { field } void test2() { method() } void test3() { this.field } void test4() { this.method() } void test5() { super.@field } void test6() { super.field } void test7() { super.method() } void test8() { (this.&method)() } void test9() { (super.&method)() } def testX() { (Foo.&method.curry(this))() // GROOVY-5051 workaround } } /*line 40*/ def bar = new Bar() shouldFail(MissingPropertyException, bar.&test1) shouldFail(MissingMethodException , bar.&test2) shouldFail(MissingPropertyException, bar.&test3) shouldFail(MissingMethodException , bar.&test4) shouldFail(MissingFieldException , bar.&test5) shouldFail(MissingPropertyException, bar.&test6) shouldFail(MissingMethodException , bar.&test7) shouldFail(MissingMethodException , bar.&test8) shouldFail(MissingMethodException , bar.&test9) assert bar.testX() == 'method' ''' } {code} was (Author: emilles): Consistency is now quite good. The only subversive access that remains is acquiring a method closure for the parent class and binding this with curry. {code:groovy} @Test void 'testGROOVY 8999 9851'() { assertScript '''import static groovy.test.GroovyAssert.shouldFail class Foo { private String field = 'field' private String method() { 'method' } } class Bar extends Foo { void test1() { field } void test2() { method() } void test3() { this.field } void test4() { this.method() } void test5() { super.@field } void test6() { super.field } void test7() { super.method() } void test8() { (this.&method)() } void test9() { (super.&method)() } def testX() { (Foo.&method.curry(this))() // GROOVY-5051 workaround } } /*line 40*/ def bar = new Bar() shouldFail(MissingPropertyException, bar.&test1) shouldFail(MissingMethodException , bar.&test2) shouldFail(MissingPropertyException, bar.&test3) shouldFail(MissingMethodException , bar.&test4) shouldFail(MissingFieldException , bar.&test5) shouldFail(MissingPropertyException, bar.&test6) shouldFail(MissingMethodException , bar.&test7) shouldFail(MissingMethodException , bar.&test8) shouldFail(MissingMethodException , bar.&test9) assert bar.testX() == 'method' ''' } {code} > Private field and method use from subclass is inconsistent > ---------------------------------------------------------- > > Key: GROOVY-9851 > URL: https://issues.apache.org/jira/browse/GROOVY-9851 > Project: Groovy > Issue Type: Bug > Reporter: Eric Milles > Assignee: Eric Milles > Priority: Minor > Fix For: 4.0.0-rc-2 > > > This is probably just a slice of GROOVY-1591, GROOVY-3010, GROOVY-3142, > GROOVY-5438, et al. > Adding "super." qualifier causes strange behaviors. Consider the following: > {code:java} > class Foo { > private String field = 'field' > private String method() { 'method' } > } > class Bar extends Foo { > def baz() { > field // MissingPropertyException: No such property: field for class: Bar > method() // MissingMethodException: No signature of method: Bar.method() > this.field // MissingPropertyException: No such property: field for > class: Bar > this.method() // MissingMethodException: No signature of method: > Bar.method() > super.@field // MissingFieldException: No such field: field for class: > Bar -- fixed by GROOVY-8999 > // so far, so good -- although Groovy allows access to private fields and > methods from outside of Bar and Foo > super.field // MissingMethodException: No signature of method: > Bar.getField() -- that's strange > super.method() // returns "method" -- Why is this okay? > (super.&method)() // MissingMethodException: No signature of method: > Bar.method() is applicable for argument types: () values: [] > } > } > {code} -- This message was sent by Atlassian Jira (v8.20.10#820010)