Project

General

Profile

Actions

Bug #19166

closed

Module#remove_method can change frozen modules when there is a prepended module

Added by alanwu (Alan Wu) almost 2 years ago. Updated almost 2 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
2.7, 3.0, 3.1, dev
[ruby-core:111131]

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 issues 1 (0 open1 closed)

Related to Ruby master - Bug #19164: [3.2.0dev] Freezing an object can prevent removing methods on its classClosedActions
Actions #1

Updated by Eregon (Benoit Daloze) almost 2 years ago

  • Related to Bug #19164: [3.2.0dev] Freezing an object can prevent removing methods on its class added
Actions #2

Updated by Anonymous almost 2 years ago

  • 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

Actions

Also available in: Atom PDF

Like0
Like0Like0