Issue #14314 has been updated by Hanmac (Hans Mackowiak).


ah yeah i see the problem

comparing the dump of the two cases, the dump doesn't know that the struct might need keyword_init (might not need to know?)

the problem is that its hard coded and can't be overwritten by own dump/load methods
https://github.com/ruby/ruby/blob/trunk/marshal.c#L1792-L1830
i think there need to be a check added if the struct wants keyword_init

----------------------------------------
Bug #14314: Marshalling broken in Ruby 2.5.0 for Structs with keyword_init: true
https://bugs.ruby-lang.org/issues/14314#change-69204

* Author: jurriaan (Jurriaan Pruis)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: ruby 2.5.0p0 (2017-12-25 revision 61468) [x86_64-linux]
* Backport: 2.3: UNKNOWN, 2.4: UNKNOWN, 2.5: UNKNOWN
----------------------------------------
Steps to reproduce:

~~~ 
irb(main):001:0> Foo = Struct.new(:foo)
=> Foo
irb(main):002:0> Marshal.load(Marshal.dump(Foo.new('a')))
=> #<struct Foo foo="a">
irb(main):003:0> Bar = Struct.new(:bar, keyword_init: true)
=> Bar(keyword_init: true)
irb(main):004:0> Marshal.load(Marshal.dump(Bar.new(bar: 'a')))
Traceback (most recent call last):
        3: from /home/jurriaan/.rubies/ruby-2.5.0/bin/irb:11:in `<main>'
        2: from (irb):4
        1: from (irb):4:in `load'
ArgumentError (wrong number of arguments (given 1, expected 0))
~~~

I expected the keyword_init: true struct to unmarshal correctly.

This issue is caused by marshal.c calling the struct initializer with regular arguments instead of keyword arguments.



-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>