codeconsole commented on PR #3050:
URL: https://github.com/apache/groovy/pull/3050#issuecomment-7083259216

   Thank you for the careful review.
   
   The non-`this` receiver case is fixed in 07dce78 and generalized in 5adeb0e. 
When the type checker selects a method that the receiver lacks and an enclosing 
instance of it has, it marks the call with the receiver type. The call writer 
then calls the method on that receiver's enclosing instance, through its 
`this$0` chain. Your script now gives `[im:A, im:A, im:A, im:B, im:A]` under 
`@CompileStatic` too.
   
   The same holds for:
   - `Sub.this.im()`;
   - a closure, a native lambda, a safe call (also `this?.im()`) and a spread 
call;
   - a closure delegate (`other.with { im() }`);
   - a class nested in `Sub`, and a receiver of a subclass of `Sub`;
   - an anonymous class created in a closure;
   - a plain inner class, also for a public method of the outer class;
   - the operators `other + x`, `other[i]` and `x in other`.
   
   A method of the receiver itself comes first, as dynamic Groovy only turns to 
the enclosing instance for a method the receiver lacks: with a public 
`Sub.m(Object)`, `other.m('x')` calls it rather than a private `Box.m(String)`. 
`new Sub().im()` written in `Box` itself still runs on that `Sub`. `Box x = 
other; x.im()` and `((Box) other).im()` keep calling on the object under 
`@CompileStatic`, as javac does for the static type `Box` (GROOVY-12513). 
`testCallToPrivateMethodOfEnclosingClassThroughOtherReceiverInInnerSubclass` 
and `testCallToMethodOfEnclosingInstanceOfReceiver` cover these, and both fail 
without the change.
   
   For property syntax, `@TypeChecked` accepts `other.p` and `other.q = v` for 
a private accessor of the enclosing class through another receiver of the 
calling class (69f2236), where the run time falls back to the enclosing 
instance (GROOVY-12621). `@CompileStatic` reports "No such property" for them 
instead of using the receiver, as master did. For a private field, `other.f` 
under `@CompileStatic` still reads `other`'s own field, as GROOVY-12621's 
`testPrivateFieldOfSuperclassViaReceiverOfCallingClass` pins it, so for a 
non-`this` receiver methods and fields differ under static compilation. 
Aligning the fields would mean changing that master test.
   
   The guide paragraph is reworded in 28583c9 and c51a496: "none of the private 
members", the enum constant body and anonymous-subclass-in-a-static-context 
exception, `sub.name` limited to `Base` and the classes nested in it, the 
GROOVY-12513 flow-typing split restricted to private instance members outside 
`Base`, private static members staying reachable, and the inner-class cases.
   
   You are right about `super.im()` and `((Box) sub).im()`: dynamic Groovy and 
`@TypeChecked` throw `MissingMethodException` for both, as for a `Box` 
parameter that holds a `Sub`. Only `@CompileStatic` and javac run them. The 
description is corrected, and it now states the `@CompileStatic` compatibility 
break explicitly.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to