paulk-asert commented on code in PR #2499:
URL: https://github.com/apache/groovy/pull/2499#discussion_r3176199060


##########
src/main/java/org/codehaus/groovy/runtime/ScriptBytecodeAdapter.java:
##########
@@ -998,4 +998,34 @@ public static Object bitwiseNegate(final Object value) 
throws Throwable {
             throw unwrap(gre);
         }
     }
+
+    /**
+     * GEP-15: dispatcher for compound-assignment operators in dynamic Groovy.
+     * If {@code receiver} responds to {@code assignName} with the supplied 
argument,
+     * invoke it and return {@code receiver} (so the caller's STORE assigns 
the same
+     * reference back, leaving the in-place mutation visible). Otherwise fall 
back to
+     * {@code baseName} and return its result for the caller to assign.
+     */
+    public static Object compoundAssign(final Object receiver, final Object 
arg,
+                                        final String assignName, final String 
baseName) throws Throwable {
+        if (receiver != null) {
+            MetaClass mc = InvokerHelper.getMetaClass(receiver);
+            if (!mc.respondsTo(receiver, assignName, new 
Object[]{arg}).isEmpty()) {
+                mc.invokeMethod(receiver, assignName, arg);
+                return receiver;
+            }
+        }
+        return InvokerHelper.invokeMethod(receiver, baseName, arg);
+    }
+
+    /**
+     * GEP-15: helper for {@code @OperatorRename(plusAssign="...")} expression 
rewrites.
+     * The user's renamed name is authoritative (no fallback), and the 
expression value of
+     * {@code x op= y} is the (mutated) {@code x}, not the called method's 
return value.
+     */
+    public static Object invokeRenamedCompoundAssign(final Object receiver, 
final Object arg,
+                                                     final String name) throws 
Throwable {
+        InvokerHelper.invokeMethod(receiver, name, arg);
+        return receiver;

Review Comment:
   reworked this



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