diff options
-rw-r--r-- | prism_compile.c | 2 | ||||
-rw-r--r-- | test/.excludes-parsey/TestDefined.rb | 1 | ||||
-rw-r--r-- | test/ruby/test_defined.rb | 20 |
3 files changed, 22 insertions, 1 deletions
diff --git a/prism_compile.c b/prism_compile.c index 39fa6e25fb..6de3f69c29 100644 --- a/prism_compile.c +++ b/prism_compile.c @@ -4213,7 +4213,7 @@ pm_compile_defined_expr0(rb_iseq_t *iseq, const pm_node_t *node, const pm_node_l // If we have empty parentheses, then we want to return "nil". dtype = DEFINED_NIL; } - else if (PM_NODE_TYPE_P(cast->body, PM_STATEMENTS_NODE) && ((const pm_statements_node_t *) cast->body)->body.size == 1) { + else if (PM_NODE_TYPE_P(cast->body, PM_STATEMENTS_NODE) && !PM_NODE_FLAG_P(cast, PM_PARENTHESES_NODE_FLAGS_MULTIPLE_STATEMENTS)) { // If we have a parentheses node that is wrapping a single statement // then we want to recurse down to that statement and compile it. pm_compile_defined_expr0(iseq, ((const pm_statements_node_t *) cast->body)->body.nodes[0], node_location, ret, popped, scope_node, in_condition, lfinish, false); diff --git a/test/.excludes-parsey/TestDefined.rb b/test/.excludes-parsey/TestDefined.rb new file mode 100644 index 0000000000..ae2a2a6270 --- /dev/null +++ b/test/.excludes-parsey/TestDefined.rb @@ -0,0 +1 @@ +exclude(:test_defined_paren_void_stmts, "defined? (x;)") diff --git a/test/ruby/test_defined.rb b/test/ruby/test_defined.rb index 3a8065d959..db1fdc8e25 100644 --- a/test/ruby/test_defined.rb +++ b/test/ruby/test_defined.rb @@ -243,6 +243,26 @@ class TestDefined < Test::Unit::TestCase assert_nil(defined?(p () + 1)) end + def test_defined_paren_void_stmts + assert_equal("expression", defined? (;x)) + assert_equal("expression", defined? (x;)) + assert_nil(defined? ( + + x + + )) + + x = 1 + + assert_equal("expression", defined? (;x)) + assert_equal("expression", defined? (x;)) + assert_equal("local-variable", defined? ( + + x + + )) + end + def test_defined_impl_specific feature7035 = '[ruby-core:47558]' # not spec assert_predicate(defined?(Foo), :frozen?, feature7035) |