From d55c26103a3a6850fb90d0943304df1b41bb7a51 Mon Sep 17 00:00:00 2001 From: eileencodes Date: Tue, 23 Jul 2024 15:12:12 -0400 Subject: [PATCH] [Prism] Use `putnil` for nil kwargs, not `putobject {}` This addresses one of the issues in the `test_kw_splat_nil` failure, but doesn't make the test pass because of other changes that need to be made to Prism directly. One issue was when we have the following code Prism was using `putobject` with an empty hash whereas the parse.y parser used `putnil`. ```ruby :ok.itself(**nil) ``` Before: ``` 0000 putobject :ok ( 1)[Li] 0002 putobject {} 0004 opt_send_without_block 0006 leave ``` After: ``` == disasm: #@test2.rb:1 (1,0)-(1,17)> 0000 putobject :ok ( 1)[Li] 0002 putnil 0003 opt_send_without_block 0005 leave ``` Related to ruby/prism#2935. --- prism_compile.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prism_compile.c b/prism_compile.c index 667ff08dc2e353..5983489dd0a4ec 100644 --- a/prism_compile.c +++ b/prism_compile.c @@ -1475,7 +1475,7 @@ pm_compile_hash_elements(rb_iseq_t *iseq, const pm_node_t *node, const pm_node_l // This is only done for method calls and not for literal // hashes, because literal hashes should always result in a // new hash. - PUSH_INSN1(ret, location, putobject, rb_hash_new()); + PUSH_INSN(ret, location, putnil); } else if (first_element) { // **{} appears as the first keyword argument, so it may be