Project

General

Profile

Actions

Bug #19164

closed

[3.2.0dev] Freezing an object can prevent removing methods on its class

Added by byroot (Jean Boussier) over 1 year ago. Updated over 1 year ago.

Status:
Closed
Assignee:
-
Target version:
ruby -v:
ruby 3.2.0dev (2022-11-30T08:20:38Z master c8bfbbc25e) [arm64-darwin22]
[ruby-core:111116]

Description

The following snippet showcase the bug. It passes on 3.1 and older, but fails on 3.2.0

klass = Class.new
klass.prepend(Module.new)

klass.new.freeze
klass.define_method(:bar) {} # works
klass.remove_method(:bar) # raise FrozenError

Bisecting with this script points me to e7b1ff984fde859a7778dec564731eb79392406f, which suggest some part of the codebase might be misusing some user flags.

I have a patch that fix this script but I doubt it's the right fix, I'll be working with @jemmai (Jemma Issroff) and @tenderlovemaking (Aaron Patterson) to find a proper fix.

I'm opening this ticket to make sure it's addressed before the 3.2.0 final release.


Related issues 1 (0 open1 closed)

Related to Ruby master - Bug #19166: Module#remove_method can change frozen modules when there is a prepended moduleClosedActions
Actions #1

Updated by byroot (Jean Boussier) over 1 year ago

  • Description updated (diff)
Actions #2

Updated by Eregon (Benoit Daloze) over 1 year ago

  • Related to Bug #19166: Module#remove_method can change frozen modules when there is a prepended module added
Actions #3

Updated by Anonymous over 1 year 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
Like0Like0Like0