proc.c: fix Method#== for aliased methods and comparison bug; fix #6668

follow alias chains in mrb_proc_eql() to compare underlying procs,
making Method#== return true for aliased methods as in CRuby.

also fix typo where p1 was checked instead of p2 in CFUNC comparison.

Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
Yukihiro "Matz" Matsumoto
2025-10-27 22:34:11 +09:00
parent 29b3405283
commit ffd3252dd0
+13 -1
View File
@@ -340,8 +340,20 @@ mrb_proc_eql(mrb_state *mrb, mrb_value self, mrb_value other)
const struct RProc *p1 = mrb_proc_ptr(self);
const struct RProc *p2 = mrb_proc_ptr(other);
/* Follow alias chains to get the real procs */
while (p1 && MRB_PROC_ALIAS_P(p1)) {
p1 = p1->upper;
}
while (p2 && MRB_PROC_ALIAS_P(p2)) {
p2 = p2->upper;
}
/* If either pointer is NULL after following aliases, they can't be equal */
if (!p1 || !p2) return FALSE;
if (MRB_PROC_CFUNC_P(p1)) {
if (!MRB_PROC_CFUNC_P(p1)) return FALSE;
if (!MRB_PROC_CFUNC_P(p2)) return FALSE;
if (p1->body.func != p2->body.func) return FALSE;
}
else if (MRB_PROC_CFUNC_P(p2)) return FALSE;