Actions
Bug #22614
closedRegressions: Adverse interactions between (unused) refinements and UnboundMethod#bind_call
Bug #22614:
Regressions: Adverse interactions between (unused) refinements and UnboundMethod#bind_call
Description
# a.rb
module M; end
class A < Array; include M; end
using(Module.new { refine(M) { def first = super } })
p A.instance_method(:first).bind_call(0x6f56)
# [BUG] Segmentation fault at 0x000000000000dead
__END__
Correct NoMethodError in v4.0.10, but regressed to a crash on trunk.
(b3e890bf95 "Fix Module#instance_method directly on module for refined
methods")
# b.rb
module M; def first = super; end
class A < Array; include M; end
module R; refine(M) { def first = 1 }; end # never using'ed
p A.new.method(:first).unbind.bind_call(0x6f56)
# [BUG] Segmentation fault at 0x000000000000dead
__END__
Behavior of this changed since a838f980f5 (v3.4.x) and then since a4dff09be7
"[Bug #21673] Fix resolving refined module-defined method" (v4.0.x, and v3.4.8)
# c.rb
class C1; def m = :C1; end; class U; end
module M2; def m = super; end
U.include M2
p((U.new.method(:m).unbind.bind_call(C1.new) rescue $!.class))
module R; refine(M2) { def m = :unused }; end
p((U.new.method(:m).unbind.bind_call(C1.new) rescue $!.class))
__END__
:C1
NoMethodError
Should be :C1 twice, since the never-activated refinement shouldn't
change the output. v3.3.x was correct.
Updated by shugo (Shugo Maeda) 1 day ago
- Status changed from Open to Closed
Applied in changeset git|2c15e9fe33539a3ef3c471efbd005e2e075e135d.
Fix super in a refined module method rebound to another class
Once a module method is refined, even by an unused refinement, its
entry wraps the original one. UnboundMethod#bind did not update
defined_class of the wrapped entry when the entry taken from a Method
already had defined_class, so super was looked up from the ancestors
of the original class and could call a method of an unrelated class.
[Bug #22614]
Co-Authored-By: Claude Fable 5.2 noreply@anthropic.com
Updated by shugo (Shugo Maeda) 1 day ago
ยท Edited
- Backport changed from 3.3: UNKNOWN, 3.4: UNKNOWN, 4.0: UNKNOWN to 3.3: REQUIRED, 3.4: REQUIRED, 4.0: REQUIRED
The following commits need backporting:
- 2c15e9fe33 (super in a module method with an unused refinement): 3.4 and 4.0
- b870c03951 (Method#super_method after bind): 3.3, 3.4, and 4.0
Actions