kernel.c: regression on struct/array/hash == override with super; fix #6660

when overriding struct#==, array#==, or hash#== with super, the recursion
detection incorrectly treated the super call as a circular reference. this
was caused by commit 5ca2d442 which added recursion detection.

the fix introduces mrb_recursive_func_p that starts from ci[-2] instead of
ci[-1], skipping the immediate parent frame which may be a ruby override
calling super. equality methods (==, eql?) now use this function, while
inspect methods keep using mrb_recursive_method_p for immediate circular
reference detection.

Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
Yukihiro "Matz" Matsumoto
2025-11-12 07:11:12 +09:00
parent 4795b7e3ca
commit f4fb41b528
5 changed files with 37 additions and 6 deletions
+2 -2
View File
@@ -1890,7 +1890,7 @@ mrb_ary_eq(mrb_state *mrb, mrb_value ary1)
if (n == 0) return mrb_false_value();
/* Check for recursion */
if (MRB_RECURSIVE_BINARY_P(mrb, MRB_OPSYM(eq), ary1, ary2)) {
if (MRB_RECURSIVE_BINARY_FUNC_P(mrb, MRB_OPSYM(eq), ary1, ary2)) {
return mrb_false_value();
}
@@ -1921,7 +1921,7 @@ mrb_ary_eql(mrb_state *mrb, mrb_value ary1)
if (n == 0) return mrb_false_value();
/* Check for recursion */
if (MRB_RECURSIVE_BINARY_P(mrb, MRB_SYM_Q(eql), ary1, ary2)) {
if (MRB_RECURSIVE_BINARY_FUNC_P(mrb, MRB_SYM_Q(eql), ary1, ary2)) {
return mrb_false_value();
}