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
@@ -605,7 +605,7 @@ mrb_struct_equal(mrb_state *mrb, mrb_value s)
}
/* Check for recursion */
if (MRB_RECURSIVE_BINARY_P(mrb, MRB_OPSYM(eq), s, s2)) {
if (MRB_RECURSIVE_BINARY_FUNC_P(mrb, MRB_OPSYM(eq), s, s2)) {
return mrb_false_value();
}
@@ -649,7 +649,7 @@ mrb_struct_eql(mrb_state *mrb, mrb_value s)
}
/* Check for recursion */
if (MRB_RECURSIVE_BINARY_P(mrb, MRB_SYM_Q(eql), s, s2)) {
if (MRB_RECURSIVE_BINARY_FUNC_P(mrb, MRB_SYM_Q(eql), s, s2)) {
return mrb_false_value();
}