Issue #20319 has been updated by jeremyevans0 (Jeremy Evans).
I looked into this and the current behavior is deliberate, as there is a comment stating
`should not propagate to meta-meta-class` (see `rb_freeze_singleton_class` definition in
`class.c`). See related commit commit:d9a597408f0f192ff25ab51e1e6733fe6fefc01b.
Freezing the singleton class of the singleton class breaks
`TestModule#test_frozen_singleton_class`. I came up with a solution that fixes this by
walking down the attached object chain to make sure it ends in the object being frozen.
Not sure that is correct, but it does appear to pass CI:
https://github.com/ruby/ruby/pull/10245
----------------------------------------
Bug #20319: Singleton class is being frozen lazily in some cases
https://bugs.ruby-lang.org/issues/20319#change-107210
* Author: andrykonchin (Andrew Konchin)
* Status: Open
* ruby -v: 3.2.2
* Backport: 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN
----------------------------------------
I've noticed suspicious behaviour (it doesn't affect anything in practice for me
though) when an object becomes frozen only its own singleton class becomes frozen
immediately.
A singleton class of the object immediate singleton class becomes frozen lazily after
`#singleton_class` method call:
```ruby
o = Object.new
klass = o.singleton_class.singleton_class
o.freeze
puts klass.frozen? # false <== here we expect true
puts o.singleton_class.singleton_class.frozen? # true
puts klass.frozen? # true
```
I would expect all created (and visible to user) singleton classes in an object singleton
classes chain to become frozen immediately when the object gets frozen.
--
https://bugs.ruby-lang.org/