Bug #11027
closedNamed Argument assignment from Hash failure
Description
I am call a method, which has named arguments, a Hash, which then as expected, maps the keys of the Hash to the argument names.
I boiled down a problem scenario wherein it fails to do this. In the code below the argument i_field2 of the ack() method, is failing to be set from the Hash. It gets set to nil.
This also occurs in 2.2.0p0.
require 'base64'
def ack(i_field1:,i_field2:,**i_others)
puts '-'*79
puts i_field1.inspect
puts ">>> #{i_field2.inspect} <<< SHOULD be 'field2'"
puts i_others.inspect
end
# create the marshaled hash in another execution
#t_args = {i_field1:"field1",i_field2:"field2",something:"something"}
#puts Base64.strict_encode64(Marshal.dump(t_args))
#exit
t_marshal = 'BAh7CDoNaV9maWVsZDFJIgtmaWVsZDEGOgZFVDoNaV9maWVsZDJJIgtmaWVsZDIGOwZUOg5zb21ldGhpbmdJIg5zb21ldGhpbmcGOwZU'
t_args = Marshal.load(Base64.strict_decode64(t_marshal))
puts t_args.inspect
# => {:i_field1=>"field1", :i_field2=>"field2", :something=>"something"}
ack(t_args)
#_ = { something:'?' } # makes it work
#_ = { :something => '?' } # makes it work
#_ = :something # makes it work
Updated by alangano (Alan Gano) over 9 years ago
Restatement:
I have a method with named arguments. I am calling it with a Hash, whose keys match up with the names of the method arguments.
This has been working.
I boiled down a problem scenario wherein it fails to do this. In the code below the argument i_field2 of the ack() method, is failing to be set from the Hash. It gets set to nil.
This also occurs in 2.2.0p0.
Formatting fix ...
require 'base64'
def ack(i_field1:,i_field2:,**i_others)
puts '-'*79
puts i_field1.inspect
puts ">>> #{i_field2.inspect} <<< SHOULD be 'field2'"
puts i_others.inspect
end
# create the marshaled hash in another execution
#t_args = {i_field1:"field1",i_field2:"field2",something:"something"}
#puts Base64.strict_encode64(Marshal.dump(t_args))
#exit
t_marshal = 'BAh7CDoNaV9maWVsZDFJIgtmaWVsZDEGOgZFVDoNaV9maWVsZDJJIgtmaWVsZDIGOwZUOg5zb21ldGhpbmdJIg5zb21ldGhpbmcGOwZU'
t_args = Marshal.load(Base64.strict_decode64(t_marshal))
puts t_args.inspect
# => {:i_field1=>"field1", :i_field2=>"field2", :something=>"something"}
ack(t_args)
#_ = { something:'?' } # makes it work
#_ = { :something => '?' } # makes it work
#_ = :something # makes it work
Updated by nobu (Nobuyoshi Nakada) over 9 years ago
- Description updated (diff)
Marshal is not mandatory.
It can reproduce with a dynamic symbol keyword argument.
ack(i_field1:"field1", i_field2:"field2", "something".intern=>"something")
Updated by nobu (Nobuyoshi Nakada) over 9 years ago
- Status changed from Open to Assigned
- Assignee set to ko1 (Koichi Sasada)
Ko1 is going to fix this issue by advancing sp
prior to arguments setup instead of mark_stack_len
.
Updated by ko1 (Koichi Sasada) over 9 years ago
- Backport changed from 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN to 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: REQUIRED
Updated by ko1 (Koichi Sasada) over 9 years ago
- Status changed from Assigned to Closed
- % Done changed from 0 to 100
Applied in changeset r50172.
- vm_args.c: protect value stack from calling other methods
during complex parameter setting process (splat, kw, and so on).
[Bug #11027] - vm_core.h: remove rb_thead_t::mark_stack_len.
With this modification, we don't need to use th->mark_stack_len. - test/ruby/test_keyword.rb: add a test.
- cont.c (cont_capture): catch up this fix.
- vm.c (rb_thread_mark): ditto.
Updated by nobu (Nobuyoshi Nakada) over 9 years ago
- Has duplicate Bug #11091: Symbolized Strings May Break Keyword Arguments added
Updated by nobu (Nobuyoshi Nakada) over 9 years ago
- Backport changed from 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: REQUIRED to 2.0.0: DONTNEED, 2.1: DONTNEED, 2.2: REQUIRED
Updated by nagachika (Tomoyuki Chikanaga) over 9 years ago
- Backport changed from 2.0.0: DONTNEED, 2.1: DONTNEED, 2.2: REQUIRED to 2.0.0: DONTNEED, 2.1: DONTNEED, 2.2: DONE
Backorted into ruby_2_2
branch at r50562.
Updated by nagachika (Tomoyuki Chikanaga) over 9 years ago
- Related to Bug #11382: Keyword arguments randomly nullified added