Copilot commented on code in PR #2710:
URL: https://github.com/apache/groovy/pull/2710#discussion_r3576680527
##########
src/main/java/groovy/lang/Closure.java:
##########
@@ -1422,5 +1446,51 @@ private static Method findOverride(Class<?> type,
Class<?>... params) {
return null;
}
}
+
+ /**
+ * Finds the single unambiguous one-argument {@code call} override
with a declared
+ * (non-Object) parameter type (GROOVY-12164). Array-typed parameters
are skipped —
+ * that shape belongs to vararg collection, which is metaclass work —
as are bridge
+ * methods (their erased twin is the real override) and overloaded
typed overrides
+ * (ambiguous: the metaclass performs the selection).
+ *
+ * @param type the closure subclass
+ * @return the override, or null when absent, ambiguous, or
inaccessible
+ */
+ private static Method findTypedOneArgOverride(Class<?> type) {
+ Method candidate = null;
+ for (Method m : type.getMethods()) {
+ if (m.getParameterCount() != 1 || !"call".equals(m.getName())
+ || m.isBridge() || m.getDeclaringClass() ==
Closure.class) {
+ continue;
+ }
Review Comment:
findTypedOneArgOverride can currently treat a public *static* call(T) method
as the cached instance override (because getMethods() includes static methods).
If a Closure subclass happens to declare a static call(T), the fast path would
invoke it even though it is not an instance override, changing behavior vs the
metaclass doCall fallback. Filter out static methods (and optionally synthetic
ones) when selecting the typed candidate.
--
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]