From 38e3cafe62637b138700e04a8a6a1ee73fe5a5f2 Mon Sep 17 00:00:00 2001 From: Kevin Newton Date: Thu, 28 Sep 2023 10:51:57 -0400 Subject: Compile implicit nodes --- prism_compile.c | 13 +++++++++++++ test/ruby/test_compile_prism.rb | 3 +++ 2 files changed, 16 insertions(+) diff --git a/prism_compile.c b/prism_compile.c index b4c5fc89df..9f736ebdc4 100644 --- a/prism_compile.c +++ b/prism_compile.c @@ -1512,6 +1512,19 @@ pm_compile_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *const ret, } return; } + case PM_IMPLICIT_NODE: { + // Implicit nodes mark places in the syntax tree where explicit syntax + // was omitted, but implied. For example, + // + // { foo: } + // + // In this case a method call/local variable read is implied by virtue + // of the missing value. To compile these nodes, we simply compile the + // value that is implied, which is helpfully supplied by the parser. + pm_implicit_node_t *cast = (pm_implicit_node_t *)node; + PM_COMPILE(cast->value); + return; + } case PM_INSTANCE_VARIABLE_AND_WRITE_NODE: { pm_instance_variable_and_write_node_t *instance_variable_and_write_node = (pm_instance_variable_and_write_node_t*) node; diff --git a/test/ruby/test_compile_prism.rb b/test/ruby/test_compile_prism.rb index 11d59a4373..6dc4f70c49 100644 --- a/test/ruby/test_compile_prism.rb +++ b/test/ruby/test_compile_prism.rb @@ -312,6 +312,9 @@ module Prism test_prism_eval("{ a: :a }") test_prism_eval("{ a: :a, b: :b }") test_prism_eval("a = 1; { a: a }") + test_prism_eval("a = 1; { a: }") + test_prism_eval("{ to_s: }") + test_prism_eval("{ Prism: }") end ############################################################################ -- cgit v1.2.3