diff options
author | Kevin Newton <kddnewton@gmail.com> | 2023-09-28 10:51:57 -0400 |
---|---|---|
committer | Kevin Newton <kddnewton@gmail.com> | 2023-09-29 09:51:23 -0400 |
commit | 38e3cafe62637b138700e04a8a6a1ee73fe5a5f2 (patch) | |
tree | 7b2347aa1ff1c578ff0ecb17954f1d28f67c5ca1 | |
parent | 396042a25c6c8f84cd08f9e5f10d46b834802c9f (diff) | |
download | ruby-38e3cafe62637b138700e04a8a6a1ee73fe5a5f2.tar.gz |
Compile implicit nodes
-rw-r--r-- | prism_compile.c | 13 | ||||
-rw-r--r-- | test/ruby/test_compile_prism.rb | 3 |
2 files changed, 16 insertions, 0 deletions
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 ############################################################################ |