Actions
Bug #18141
closedMarshal load with proc yield objects before they are fully initialized
Bug #18141:
Marshal load with proc yield objects before they are fully initialized
Description
I assume this is a bug because I can't find any spec or test for this behaviour:
Consider the following script:
payload = Marshal.dump("foo")
Marshal.load(payload, -> (obj) {
if obj.is_a?(String)
p [obj, obj.encoding]
end
obj
})
p [:final, string, string.encoding]
outputs:
So Marshal call the proc before the string get its encoding assigned, this is because the encoding is stored alongside as a TYPE_IVAR. I think in such cases Marshal should delay calling the proc until the object is fully restored.
A corollary to this behaviour is that the following code:
raises with can't modify frozen String: "foo" (FrozenError).
The same happens with any instance variable on Array or Hash
Actions