diff options
| author | eileencodes <eileencodes@gmail.com> | 2024-01-17 10:44:01 -0500 |
|---|---|---|
| committer | Kevin Newton <kddnewton@gmail.com> | 2024-01-17 17:21:29 -0500 |
| commit | fb1eed3f7034c9219f83d086011296f8955bcddc (patch) | |
| tree | 2db014b4b0b29d5025d3568b999fb9baa173771f | |
| parent | 7460820fec8086d14c820d8e8f8042811105470f (diff) | |
[Prism] Implement defined? for PM_FOR_NODE
Ruby code:
```ruby
defined?(for i in [1,2] do; i; end)
```
Instructions:
```
"********* Ruby *************"
== disasm: #<ISeq:<compiled>@<compiled>:1 (1,0)-(59,43)>
0000 putobject "expression" ( 59)[Li]
0002 leave
"********* PRISM *************"
== disasm: #<ISeq:<compiled>@<compiled>:58 (58,0)-(58,43)>
0000 putobject "expression" ( 58)[Li]
0002 leave
```
Related: ruby/prism#2188
| -rw-r--r-- | prism_compile.c | 1 | ||||
| -rw-r--r-- | test/ruby/test_compile_prism.rb | 1 |
2 files changed, 2 insertions, 0 deletions
diff --git a/prism_compile.c b/prism_compile.c index e8eab6ed35..5fe98a3737 100644 --- a/prism_compile.c +++ b/prism_compile.c @@ -2542,6 +2542,7 @@ pm_compile_defined_expr0(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *co case PM_DEF_NODE: case PM_DEFINED_NODE: case PM_FLOAT_NODE: + case PM_FOR_NODE: case PM_HASH_NODE: case PM_IMAGINARY_NODE: case PM_INTEGER_NODE: diff --git a/test/ruby/test_compile_prism.rb b/test/ruby/test_compile_prism.rb index 98083c4368..5b301b6f26 100644 --- a/test/ruby/test_compile_prism.rb +++ b/test/ruby/test_compile_prism.rb @@ -253,6 +253,7 @@ module Prism assert_prism_eval("defined?(case [1, 2, 3]; in [1, 2, 3]; 4; end)") assert_prism_eval("defined?(class PrismClassA; end)") assert_prism_eval("defined?(def prism_test_def_node; end)") + assert_prism_eval("defined?(for i in [1,2] do; i; end)") end def test_GlobalVariableReadNode |
