Bug #19166
closed
Module#remove_method can change frozen modules when there is a prepended module
Added by alanwu (Alan Wu) about 2 years ago.
Updated about 2 years ago.
Description
module A
prepend Module.new # remove this line and you'd get FrozenError as expected
def foo; end
freeze
remove_method :foo # remove works even though module is frozen!
p instance_methods(false) # => []
end
Old bug, reproduces in 2.7 through 3.1 and on master. Found while investigating #19164.
- Related to Bug #19164: [3.2.0dev] Freezing an object can prevent removing methods on its class added
- Status changed from Open to Closed
Applied in changeset git|3d272b0fc822f5c2e9c716377b7fcecf15426b27.
Module#remove_method: Check frozen on the right object
Previously, the frozen check happened on RCLASS_ORIGIN(self)
, which
can return an iclass. The frozen check is supposed to respond to objects
that users can call methods on while iclasses are hidden from users.
Other mutation methods like Module#{define_method,alias_method,public}
don't do this. Check frozen status on the module itself.
Fixes [Bug #19164] and [Bug #19166].
Co-authored-by: Alan Wu XrXr@users.noreply.github.com
Also available in: Atom
PDF
Like0
Like0Like0