[ 
https://issues.apache.org/jira/browse/GROOVY-12614?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18144702#comment-18144702
 ] 

ASF GitHub Bot commented on GROOVY-12614:
-----------------------------------------

paulk-asert commented on PR #3297:
URL: https://github.com/apache/groovy/pull/3297#issuecomment-6871707474

   Thanks Daniel, all of these checked out. I've pushed 3ef9259bb1 in response.
   
   **1. Closure within a lambda.** Fixed: the innermost construct now decides, 
so a declared property in a closure within a lambda goes through the accessor 
for reads and writes, and a lambda within a closure still uses the field. 
`testPropertyInClosureWithinLambdaUsesTheAccessor` locks this in all three 
modes. One deviation is recorded in the NOTE: the simple name is not offered to 
the closure's delegate there (it behaves as `this.name`), because leaving it 
for the closure to resolve hits the GROOVY-12602 `ClassCastException` under 
`@CompileStatic`.
   
   **2. `++` / `--`.** I've taken your second option. The Terms no longer claim 
these are the same form of reference, static rule 4 and the "Prefix and postfix 
operations" section say what happens, and 
`testIncrementOfStaticAccessorIsNotACallOfTheTraitAccessor` locks the current 
results in all three modes, including the mixed `@CompileStatic` one. Increment 
and decrement of a trait's own fields are still rejected (GROOVY-6689), and I'd 
rather handle both together there than complete half of it here.
   
   **Other notes.**
   - The NOTE now lists the `@Virtual` cell for `@CompileStatic`.
   - GROOVY-12608 under `@CompileStatic` is locked (the lambda reads the 
accessor, so `1`), and since master returns `42` there I've added a 
`COMPATIBILITY.md` entry for it.
   - The customizer case is locked too. It is a little worse than "document or 
test": a plain lambda `() -> cnt` fails with `MissingFieldException` when 
`@CompileStatic` comes from a customizer. Master fails there as well, so it is 
recorded as an open cell, not a regression.
   - The `invokestatic` alignment for a super-trait accessor in a method body 
I'll leave for a follow-up, as you suggest.
   - I've held back the `COMPATIBILITY.md` entry for the GROOVY-12597 message 
until the backport decision is made.




> Trait code reads a plain static accessor as a property through the 
> implementing class in dynamic and @TypeChecked code, but declarer-bound under 
> @CompileStatic and in the method form
> --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: GROOVY-12614
>                 URL: https://issues.apache.org/jira/browse/GROOVY-12614
>             Project: Groovy
>          Issue Type: Bug
>    Affects Versions: 6.0.0
>            Reporter: Scott Murphy Heiberg
>            Priority: Major
>
> {code:groovy}
> trait T {
>     static String getLabel() { 'trait' }
>     static String sm() { label }        // property form
>     static String sm2() { getLabel() }  // method form
> }
> class C implements T { static String getLabel() { 'impl' } }
> class D implements T {}
> println([C.sm(), D.sm(), C.sm2(), D.sm2()])
> {code}
> Dynamic and @TypeChecked: [impl, trait, trait, trait]
> @CompileStatic: [trait, trait, trait, trait]
> The property form of a plain (non-@Virtual) static accessor, read from trait 
> code, dispatches through the implementing class in dynamic and type-checked 
> code, but is declarer-bound under static compilation, and the method form is 
> declarer-bound in every mode. The same holds for this.label, for an instance 
> trait method, inside closures, and for an accessor of a super trait. A 
> field-backed static property is declarer-bound in all modes.
> The traits guide says public statics are declarer-bound by default for calls 
> from other trait code and that @Virtual opts into implementing-class dispatch 
> ("For overridable static data rather than behaviour, use a @Virtual 
> accessor"). VirtualAnnotationTest/TraitStaticDispatchMatrix row09vget adds 
> @Virtual to get exactly the override-visible property read. But 
> TraitStaticDispatchMatrix.row09acc_accessorPattern_overrideVisibleToTraitBody 
> asserts the dynamic behaviour ("origin is class" for a plain accessor), with 
> a comment pointing at row 1's dispatch path, which since "GROOVY-12093 
> adjusted: out with @Anchored in with @Virtual" requires @Virtual. row09acc 
> looks like it predates that change.
> Question: which is intended? If declarer-bound is the rule, 
> TraitReceiverTransformer should call the helper for a property read or write 
> of a plain static accessor, as it does for the method form, and row09acc 
> should expect "origin is trait" (or move to @Virtual). If row09acc is the 
> rule, static compilation and the method form disagree with it. I can provide 
> the PR either way.
> Seen in 6.0.0 and on master.



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to