diff options
author | Jeremy Evans <code@jeremyevans.net> | 2019-09-27 08:07:49 -0700 |
---|---|---|
committer | Jeremy Evans <code@jeremyevans.net> | 2019-09-27 11:22:21 -0700 |
commit | d53cf854741bbf496298c5a722988d2dd84314a1 (patch) | |
tree | 9d2d8ee45b9c4bff636be7bfb993d9bb507ac0c4 /test | |
parent | 7814b6c6572446a6b64614e524d13dd423577004 (diff) | |
download | ruby-d53cf854741bbf496298c5a722988d2dd84314a1.tar.gz |
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.
Diffstat (limited to 'test')
-rw-r--r-- | test/ruby/test_struct.rb | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/test/ruby/test_struct.rb b/test/ruby/test_struct.rb index ec0a29026b..6ba28153e9 100644 --- a/test/ruby/test_struct.rb +++ b/test/ruby/test_struct.rb @@ -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) } |