1 (for consistency with this.x as a direct field access)
3 (because there is an actual field in the current class B) 
1 (because there is an actual field in the current class A)


I find the following most consistent:
1. x should refer to the field of the current class if such field exists
  to support def getX() { x /*here*/ }
2. otherwise x should go via MOP just like the regular property access from 
outside of the class
3. this.x should refer to the field of the current class if such field exists
  to support void setX(x) { this.x = x }
4. otherwise this.x should go via MOP just like the regular property access 
from outside of the class
5. for consistency with 3 super.x should refer to the field of the super class 
if such field exists and accessible without reflection
6. for consistency with 4 super.x should go via MOP but behave like Java's 
invokespecial considering only properties of the superclass (i.e. ignore 
supers’ supers)
  
—

Daniil Ovchinnikov
JetBrains

> On 26 Jun 2020, at 17:34, Milles, Eric (TR Tech, Content & Ops) 
> <eric.mil...@thomsonreuters.com> wrote:
> 
> Sorry for replying to my own...
>  
> class A {
>   def x = 1
>   def getX() { 2 }
>   def m() { return x }
> }
> print new A().m() // output 1 or 2?
>  
> class B extends A {
>   def x = 3
>   def getX() { 4 }
>   def m2() { return x }
>   def m3() { return super.x }
> }
> print new B().m3() // output 1 or 2?
> print new B().m2() // output 3 or 4?
> print new B().m() // output 1 or 2 or 3 or 4?
>  
>  
> From: Milles, Eric (TR Tech, Content & Ops) <eric.mil...@thomsonreuters.com> 
> Sent: Friday, June 26, 2020 9:25 AM
> To: dev@groovy.apache.org
> Subject: RE: "super" object expression for attribute, property, and method 
> call
>  
> Thanks for the additional reference.  Also, GROOVY-9596 helps provide some 
> additional context.
>  
> When considering "this.x" and "super.x" where "x" in both cases is a field or 
> property of the super class, I can understand the desire for consistent 
> handling.  When "x" is a member in the current class, direct field access 
> seems intuitive to me; OC raises some concern.  When "x" is a member of the 
> current class and a subclass, things start to get complicated.
>  
> class A {
>   def x = 1
>   def m() { x }
> }
> class B extends A {
>   def x = 2
>   def getX() { 3 }
> }
> new B().m() // as discussed in nabble link, should this return 1 always or 2 
> or 3?
>  
>  
> From: OCsite <o...@ocs.cz> 
> Sent: Friday, June 26, 2020 9:05 AM
> To: dev@groovy.apache.org
> Subject: Re: "super" object expression for attribute, property, and method 
> call
>  
> Hi there,
>  
> note please that IMO, this.foo definitely should go through the getFoo getter 
> if there's one; that is does not happen currently I regard as a pretty grave 
> bug, for it breaks encapsulation. Compare please e.g.
>  
> http://groovy.329449.n5.nabble.com/Inconsistency-properties-are-accessed-as-fields-within-class-td5721135.html
>  
> All the best,
> OC
>  
> 
> On 26 Jun 2020, at 15:51, Milles, Eric (TR Tech, Content & Ops) 
> <eric.mil...@thomsonreuters.com> wrote:
>  
> which means [super.x] behaves different to this.x
> 
> Yes, they would be different.  I always interpreted this behavior as 
> "references to a class member within the declaring class are direct 
> accesses".  For me, "super.x" is not a reference to a member from the 
> declaring class, so MOP is okay/expected.  Indeed, there are bugs cited that 
> expect "super.x" to drive getX() or isX() in the parent class.
> 
> Is there an explicit definition of explicit "this" and "super" qualifiers 
> with regards to fields?  I'm going off intuition and experience.  GROOVY-8999 
> tries to show that there is not consistent behavior and so it is hard to 
> fully understand what can be expected when using the super qualifier.
> 
> 
> I will proceed with proposed changes to "super.@x" and the error messages.  
> Those items don't seem controversial.
> 
> 
> -----Original Message-----
> From: Jochen Theodorou <blackd...@gmx.org> 
> Sent: Thursday, June 25, 2020 11:56 PM
> To: dev@groovy.apache.org
> Subject: Re: "super" object expression for attribute, property, and method 
> call
> 
> On 25.06.20 23:34, Milles, Eric (TR Tech, Content & Ops) wrote:
> 
> The handling for "this" and "super" are separate enough that we could support 
> different behaviors.  I think I am looking to make 2 changes to start with:
> 
> 1) super.@x cannot access a private field and does not try getX(), isX() or 
> any other alternatives.  STC should produce an error for this case.  
> Currently, if the field is not accessible, "super.getX()" is substituted and 
> so errors for "no getX() method" can be confusing.
> 
> 2) super.x does not bypass accessor methods.  So getX() if it exists, isX() 
> if its boolean, field if field is accessible and no accessor exists, and 
> finally propertyMissing/MissingPropertyException.
> 
> As you stated below, #1 is a breaking change.  Today an inaccessible super.@x 
> produces a super.getX() substitution.  And I think #2 is a refinement; if 
> user wants to bypass the accessor method, super.@x is and has been available.
> 
> which means it behaves different to this.x
> 
> 
> I suppose the third change is that when "super.x" fails, the compiler says 
> "No such property x for B" when A is really the start of the search.  Fixing 
> the error messages would also be beneficial.
> 
> +1
> 
> 
> I'm not proposing to enable access to private fields, just improve the 
> consistency of errors and remove workarounds that IMO go against the spirit 
> of ".@" operator.
> 
> this has been a story in the past  for dynamic Groovy, which is why I 
> mentioned it explicitly
> 
> bye Jochen

Reply via email to