[
https://issues.apache.org/jira/browse/GROOVY-11970?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18077760#comment-18077760
]
ASF GitHub Bot commented on GROOVY-11970:
-----------------------------------------
paulk-asert commented on code in PR #2499:
URL: https://github.com/apache/groovy/pull/2499#discussion_r3176058130
##########
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);
Review Comment:
fixed
> Provide support for compound assignment operator overloading (GEP-15)
> ---------------------------------------------------------------------
>
> Key: GROOVY-11970
> URL: https://issues.apache.org/jira/browse/GROOVY-11970
> Project: Groovy
> Issue Type: New Feature
> Reporter: Paul King
> Assignee: Paul King
> Priority: Major
>
--
This message was sent by Atlassian Jira
(v8.20.10#820010)