summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2023-09-13 23:33:19 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2023-09-15 01:09:07 +0900
commit9cb33aad55e0a2cded3b09b0509b9c53fb0fa5ae (patch)
treedd7c0bc7780efe838d9fdb865fd087fb0068a36e
parent864bb8680cee48a2bed85703dc2e4070728362d4 (diff)
[Bug #19877] Fix flip-flop in block
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/8440
-rw-r--r--parse.y4
-rw-r--r--test/ruby/test_parse.rb15
2 files changed, 19 insertions, 0 deletions
diff --git a/parse.y b/parse.y
index c209940712..be68bdf180 100644
--- a/parse.y
+++ b/parse.y
@@ -12472,6 +12472,10 @@ cond0(struct parser_params *p, NODE *node, enum cond_type type, const YYLTYPE *l
return NEW_MATCH2(node, NEW_GVAR(idLASTLINE, loc), loc);
+ case NODE_BLOCK:
+ node->nd_end->nd_head = cond0(p, node->nd_end->nd_head, type, loc);
+ break;
+
case NODE_AND:
case NODE_OR:
node->nd_1st = cond0(p, node->nd_1st, COND_IN_COND, loc);
diff --git a/test/ruby/test_parse.rb b/test/ruby/test_parse.rb
index 0f71e11f7e..2f1a522dc2 100644
--- a/test/ruby/test_parse.rb
+++ b/test/ruby/test_parse.rb
@@ -465,6 +465,21 @@ class TestParse < Test::Unit::TestCase
assert_parse_error(%q[def (:"#{42}").foo; end], msg)
end
+ def test_flip_flop
+ [
+ '((cond1..cond2))',
+ '(; cond1..cond2)',
+ '(1; cond1..cond2)',
+ '(%s(); cond1..cond2)',
+ '(%w(); cond1..cond2)',
+ '(1; (2; (3; 4; cond1..cond2)))',
+ '(1+1; cond1..cond2)',
+ ].each do |code|
+ code = code.sub("cond1", "n==4").sub("cond2", "n==5")
+ assert_equal([4,5], eval("(1..9).select {|n| true if #{code}}"))
+ end
+ end
+
def test_op_asgn1_with_block
t = Object.new
a = []