diff options
author | John Hawthorn <john@hawthorn.email> | 2022-09-25 19:54:49 -0700 |
---|---|---|
committer | John Hawthorn <john@hawthorn.email> | 2022-09-25 20:44:54 -0700 |
commit | b361bdc20036688f17f1e39a260a70254e7db9cd (patch) | |
tree | 453a3b5efb7d5ee843021d7e0a1939d4c18fc41c /test | |
parent | e3cc1a6cae0e6c88c04cd54c3afa3c022bb6772c (diff) |
[Bug #19021] Fix safe call w/ conditional assign
As of fbaac837cfba23a9d34dc7ee144d7940248222a2, when we were performing
a safe call (`o&.x=`) with a conditional assign (`||= 1`) and discarding
the result the stack would end up in a bad state due to a missing pop.
This commit fixes that by adjusting the target label of the branchnil to
be before a pop in that case (as was previously done in the
non-conditional assignment case).
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/6437
Diffstat (limited to 'test')
-rw-r--r-- | test/ruby/test_call.rb | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/test/ruby/test_call.rb b/test/ruby/test_call.rb index 67b3a936d4..88e2ddcb7b 100644 --- a/test/ruby/test_call.rb +++ b/test/ruby/test_call.rb @@ -47,12 +47,19 @@ class TestCall < Test::Unit::TestCase assert_equal(5, o.y) o&.z ||= 6 assert_equal(6, o.z) + o&.z &&= 7 + assert_equal(7, o.z) o = nil assert_nil(o&.x) assert_nothing_raised(NoMethodError) {o&.x = raise} + assert_nothing_raised(NoMethodError) {o&.x = raise; nil} assert_nothing_raised(NoMethodError) {o&.x *= raise} assert_nothing_raised(NoMethodError) {o&.x *= raise; nil} + assert_nothing_raised(NoMethodError) {o&.x ||= raise} + assert_nothing_raised(NoMethodError) {o&.x ||= raise; nil} + assert_nothing_raised(NoMethodError) {o&.x &&= raise} + assert_nothing_raised(NoMethodError) {o&.x &&= raise; nil} end def test_safe_call_evaluate_arguments_only_method_call_is_made |