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

   Thank you. The `++` / `--` gap was real and is fixed in d30b777, with 
`testOperatorOfEnclosingInstanceOfReceiver` next to 
`testCallToMethodOfEnclosingInstanceOfReceiver`.
   
   - `other++`, `++other`, `other--` and `--other`: under `@CompileStatic` they 
called `Box.next()` on `other` itself (`next:self`), where dynamic Groovy and 
`@TypeChecked` call it on the enclosing instance (`next:B`). The type checker 
now records `ENCLOSING_INSTANCE_OF_RECEIVER` on `++` and `--` as 
`findMethodOrFail` does on a binary operator, and 
`StaticTypesBinaryExpressionMultiTypeDispatcher.writePostOrPrefixMethod` passes 
it to the `next()` or `previous()` call, which `StaticInvocationWriter` then 
makes on the enclosing instance. The test covers the four forms, the value of 
`other++`, a `this` operand, an array element `array[0]++`, and a property 
`holder.sub++`.
   - `other += x` is different from what the comment suggests: dynamic Groovy 
never calls a `*Assign` method of an enclosing instance. 
`ScriptBytecodeAdapter.compoundAssign` and `IndyCompoundAssign.resolve` use 
`plusAssign` only when the receiver's own meta-class responds to it 
(`respondsTo`, which does not reach the enclosing instance), and otherwise call 
`plus` through `invokeMethod`, which does. So the type checker now keeps a 
`*Assign` method only if it is one of the receiver itself, and `other += x` 
otherwise becomes `other = other + x`, with `plus` called on the enclosing 
instance as for `other + x`. Before, both `@TypeChecked` and `@CompileStatic` 
called `Box.plusAssign` on `other`. 03be0b1 extends this to a static 
`plusAssign` of an outer class, which `item += 'x'` also picked.
   - A subscript operand was a gap of the same kind: `other[0]++` and `other[0] 
+= x`, with a private `getAt` of `Box` and a `putAt` of `Sub`, read `other[0]` 
through `other`'s own `getAt` under `@CompileStatic`, although a plain 
`other[0]` already read it through the enclosing instance. In 03be0b1 the type 
checker records that `getAt` on an assigned subscript, and the static writer 
reads with it while the write stays `other.putAt`; 
`testSubscriptUpdateWithGetAtOfEnclosingInstance` covers `++`, `--` and `+=`.
   
   Testing the neighbours of these turned up five more cases, each with a test 
that fails without its fix and gives the asserted values when run dynamically:
   
   - b3079e0: `this::helper` and `this.&helper` in an enum constant body for a 
private method of the enum, and `Sub::sm` / `Sub.&sm` for a private static 
method of a class that encloses `Sub`, run in dynamic Groovy and compiled on 
master; this change had rejected them. They compile again; a reference through 
`Sub` to a private static method of a sibling `Box`, which dynamic Groovy fails 
on, stays rejected. The guide no longer says that every private static member 
of `Base` stays reachable through `Sub`, since property syntax `Sub.name` does 
not reach a private static field or getter.
   - 479c57f: `this.im()` in a closure in an anonymous class created in a 
closure cast the outer closure to the outer class under `@CompileStatic`; the 
`this$0` walk now goes through the closure's this object, as the walk for 
another receiver already did.
   - f3f53b8: `Box b = new Sub(); b.p = 'x'` called a private 
`Box.setP(Object)` instead of `Sub.setP(String)` under `@CompileStatic`, unlike 
`b.setP('x')`.
   - 09b256f: the enclosing-instance lookup now goes from the nearest outer 
class out and stops at the first with an applicable method, as dynamic Groovy 
does (`Middle.m(Object)` before `Outer.m(String)`), and in a static method an 
instance method of the class no longer blocks a static method of an outer class 
(`m('x')` calling `Outer.m(String)`, as on master).
   - e9c5645: a private `isReady()` of a superclass no longer hides its public 
`getReady()` from `new Sub().ready`.
   
   The 18,765 core tests, the subproject tests, Checkstyle and CodeNarc pass, 
and every commit compiles on its own. The description is updated for these.
   
   The `findVisibleMethods` javadoc, in 014d4a9 and b3079e0, now states which 
private methods a reference keeps: as for a call, a private method of the enum 
of an enum constant body and a private static method of an enclosing class; 
unlike a call, no other private static method, and none for a reference made in 
the declaring class or on an anonymous class created in a static context.
   
   On the rebase: this branch has been brought up to date by merges so far, and 
the previous replies cite those commits. Rebasing onto master would rewrite 
every commit already pushed and reviewed here and needs a force-push, so their 
ids would no longer exist on the pull request. I have not done that in this 
round; I am happy to do it if you would still like a linear branch, or a squash 
or rebase merge at merge time gives master the same history.


-- 
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