If we had (in-place) deep_freeze or even just an internal version of it, we could call that after _load/marshal_load and then it would really be deeply frozen.
And that could be efficient by using a flag on objects for "deeply frozen/immutable" (which would also imply shareable).
The issue closes automatically when a commit is merged with a reference to it. I can re-open, but I'm not super hopeful about fixing these other two cases.
As explained, I think the best we can do is shallow freeze.
Shallow freezing of TYPE_USERDEF and TYPE_USRMARSHAL is not done:
2)
Marshal.load when called with freeze: true returns frozen object having #_dump method FAILED
Expected #<UserDefined:0x00007f241ebb8e58 @a=:stuff, @b=:stuff>.frozen?
to be truthy but was false
/home/eregon/code/rubyspec/core/marshal/shared/load.rb:146:in `block (5 levels) in <top (required)>'
/home/eregon/code/rubyspec/core/marshal/load_spec.rb:4:in `<top (required)>'
3)
Marshal.load when called with freeze: true returns frozen object responding to #marshal_dump and #marshal_load FAILED
Expected #<UserMarshal:0x00007f2430a2ab10 @data=:data>.frozen?
to be truthy but was false
/home/eregon/code/rubyspec/core/marshal/shared/load.rb:151:in `block (5 levels) in <top (required)>'
/home/eregon/code/rubyspec/core/marshal/load_spec.rb:4:in `<top (required)>'
ruby_bug"#19427","3.1"..."3.3"doit"returns frozen object having #_dump method"doobject=Marshal.send(@method,Marshal.dump(UserDefined.new),freeze: true)object.should.frozen?endit"returns frozen object responding to #marshal_dump and #marshal_load"doobject=Marshal.send(@method,Marshal.dump(UserMarshal.new),freeze: true)object.should.frozen?end
Backport changed from 2.7: DONTNEED, 3.0: DONTNEED, 3.1: REQUIRED, 3.2: REQUIRED to 2.7: DONTNEED, 3.0: DONTNEED, 3.1: WONTFIX, 3.2: WONTFIX
I think it's obviously a bug, but I'm concerned that changing the behavior might cause FrozenError in applications. Therefore, I have decided not to backport the changesets related to this issue.
Please feel free to raise any objections to this decision.