[Prism] Implement defined? for PM_SINGLETON_CLASS_NODE

Ruby code:

```ruby
defined?(class << self; end)
```

Instructions:

```
"********* Ruby *************"
== disasm: #<ISeq:<compiled>@<compiled>:1 (1,0)-(59,16)>
0000 putobject                              "expression"              (  59)[Li]
0002 leave
"********* PRISM *************"
== disasm: #<ISeq:<compiled>@<compiled>:58 (58,0)-(58,16)>
0000 putobject                              "expression"              (  58)[Li]
0002 leave
```

Related: ruby/prism#2188
This commit is contained in:
eileencodes 2024-01-17 11:03:28 -05:00 committed by Kevin Newton
parent d2000e0e6c
commit b5d3d61130
2 changed files with 2 additions and 0 deletions

View File

@ -2565,6 +2565,7 @@ pm_compile_defined_expr0(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *co
case PM_REGULAR_EXPRESSION_NODE:
case PM_RETRY_NODE:
case PM_RETURN_NODE:
case PM_SINGLETON_CLASS_NODE:
case PM_SOURCE_ENCODING_NODE:
case PM_SOURCE_FILE_NODE:
case PM_SOURCE_LINE_NODE:

View File

@ -259,6 +259,7 @@ module Prism
assert_prism_eval("defined?(1 => 1)")
assert_prism_eval("defined?(module M; end)")
assert_prism_eval("defined?(1.2r)")
assert_prism_eval("defined?(class << self; end)")
end
def test_GlobalVariableReadNode