mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Fix warning when doing Struct.new(:x, keyword_init: true){}
This is due to calling rb_mod_module_eval directly instead of using rb_funcall_passing_block. The problem with calling directly is it does not create a new VM frame, so rb_mod_module_eval was called with no arguments, but with the keyword given VM frame flag set, which causes problems internally.
This commit is contained in:
parent
7814b6c657
commit
d53cf85474
Notes:
git
2019-09-28 03:22:42 +09:00
2 changed files with 11 additions and 1 deletions
2
struct.c
2
struct.c
|
@ -569,7 +569,7 @@ rb_struct_s_def(int argc, VALUE *argv, VALUE klass)
|
|||
setup_struct(st, rest);
|
||||
rb_ivar_set(st, id_keyword_init, keyword_init);
|
||||
if (rb_block_given_p()) {
|
||||
rb_mod_module_eval(0, 0, st);
|
||||
rb_funcall_passing_block(st, rb_intern("module_eval"), 0, 0);
|
||||
}
|
||||
|
||||
return st;
|
||||
|
|
|
@ -119,6 +119,16 @@ module TestStruct
|
|||
end
|
||||
end
|
||||
|
||||
def test_struct_new_with_keyword_init_and_block
|
||||
struct = @Struct.new(:a, :b, keyword_init: true) do
|
||||
def c
|
||||
a + b
|
||||
end
|
||||
end
|
||||
|
||||
assert_equal(3, struct.new(a: 1, b: 2).c)
|
||||
end
|
||||
|
||||
def test_initialize
|
||||
klass = @Struct.new(:a)
|
||||
assert_raise(ArgumentError) { klass.new(1, 2) }
|
||||
|
|
Loading…
Add table
Reference in a new issue