diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-08-13 01:52:22 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-08-13 01:52:22 +0000 |
commit | a4de31c32205e4cff9ecaa1d896a5dedfcfd5560 (patch) | |
tree | b8b1700ada167c54d862c870148ccc56b2c0315b /test | |
parent | 388f1aed3da026d8307c681bb4d1d0a382d76567 (diff) | |
download | ruby-a4de31c32205e4cff9ecaa1d896a5dedfcfd5560.tar.gz |
parse.y: rescue modifier in rhs of op asgn
* parse.y (stmt, arg): rescue modifier in command op assignment
should be limited to rhs only. [ruby-core:75621] [Bug #12402]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55887 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r-- | test/ruby/test_parse.rb | 84 |
1 files changed, 78 insertions, 6 deletions
diff --git a/test/ruby/test_parse.rb b/test/ruby/test_parse.rb index 7f0177819e..434533fcab 100644 --- a/test/ruby/test_parse.rb +++ b/test/ruby/test_parse.rb @@ -876,12 +876,84 @@ x = __ENCODING__ def test_rescue_in_command_assignment bug = '[ruby-core:75621] [Bug #12402]' - v = bug - v = raise(v) rescue "ok" - assert_equal("ok", v) - v = bug - v = raise v rescue "ok" - assert_equal("ok", v) + all_assertions(bug) do |a| + a.for("lhs = arg") do + v = bug + v = raise(bug) rescue "ok" + assert_equal("ok", v) + end + a.for("lhs op_asgn arg") do + v = 0 + v += raise(bug) rescue 1 + assert_equal(1, v) + end + a.for("lhs[] op_asgn arg") do + v = [0] + v[0] += raise(bug) rescue 1 + assert_equal([1], v) + end + a.for("lhs.m op_asgn arg") do + k = Struct.new(:m) + v = k.new(0) + v.m += raise(bug) rescue 1 + assert_equal(k.new(1), v) + end + a.for("lhs::m op_asgn arg") do + k = Struct.new(:m) + v = k.new(0) + v::m += raise(bug) rescue 1 + assert_equal(k.new(1), v) + end + a.for("lhs.C op_asgn arg") do + k = Struct.new(:C) + v = k.new(0) + v.C += raise(bug) rescue 1 + assert_equal(k.new(1), v) + end + a.for("lhs::C op_asgn arg") do + v = Class.new + v::C ||= raise(bug) rescue 1 + assert_equal(1, v::C) + end + a.for("lhs = command") do + v = bug + v = raise bug rescue "ok" + assert_equal("ok", v) + end + a.for("lhs op_asgn command") do + v = 0 + v += raise bug rescue 1 + assert_equal(1, v) + end + a.for("lhs[] op_asgn command") do + v = [0] + v[0] += raise bug rescue 1 + assert_equal([1], v) + end + a.for("lhs.m op_asgn command") do + k = Struct.new(:m) + v = k.new(0) + v.m += raise bug rescue 1 + assert_equal(k.new(1), v) + end + a.for("lhs::m op_asgn command") do + k = Struct.new(:m) + v = k.new(0) + v::m += raise bug rescue 1 + assert_equal(k.new(1), v) + end + a.for("lhs.C op_asgn command") do + k = Struct.new(:C) + v = k.new(0) + v.C += raise bug rescue 1 + assert_equal(k.new(1), v) + end + a.for("lhs::C op_asgn command") do + v = Class.new + v::C ||= raise bug rescue 1 + assert_equal(1, v::C) + end + end end =begin |