diff options
author | Nobuyoshi Nakada <[email protected]> | 2024-05-16 16:22:17 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <[email protected]> | 2024-05-16 16:22:17 +0900 |
commit | 2dd46bb82ffc4dff01d7ea70922f0e407acafb4e (patch) | |
tree | 46b4acb7f794b5eceec3bf5ee710fb8a08cc9739 /test/ruby | |
parent | 9d69619623ec6b86c464b7cac911b7201f74dab7 (diff) |
[Bug #20468] Fix safe navigation in `for` variable
Diffstat (limited to 'test/ruby')
-rw-r--r-- | test/ruby/test_syntax.rb | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/test/ruby/test_syntax.rb b/test/ruby/test_syntax.rb index 7b894eee79..edc3a3cec3 100644 --- a/test/ruby/test_syntax.rb +++ b/test/ruby/test_syntax.rb @@ -1248,6 +1248,20 @@ eom assert_syntax_error("a&.x,=0", /multiple assignment destination/) end + def test_safe_call_in_for_variable + assert_valid_syntax("for x&.bar in []; end") + assert_separately([], "#{<<~"begin;"}\n#{<<~'end;'}") + begin; + foo = nil + for foo&.bar in [1]; end + assert_nil(foo) + + foo = Struct.new(:bar).new + for foo&.bar in [1]; end + assert_equal(1, foo.bar) + end; + end + def test_no_warning_logop_literal assert_warning("") do eval("true||raise;nil") |