From ffd3252dd0bd6a285bec54fe4d7c7860f175ea64 Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Mon, 27 Oct 2025 22:34:11 +0900 Subject: [PATCH] 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 --- src/proc.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/proc.c b/src/proc.c index 0292335ac..ed0a2d6b9 100644 --- a/src/proc.c +++ b/src/proc.c @@ -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;