diff options
| author | Takashi Kokubun <takashikkbn@gmail.com> | 2024-07-08 15:55:17 -0700 |
|---|---|---|
| committer | Takashi Kokubun <takashikkbn@gmail.com> | 2024-07-08 15:55:17 -0700 |
| commit | 8a2e41d34b135046957e1195a5d4f4967a82a965 (patch) | |
| tree | 8b9e1b6ab3cc9f528186ffa8246dcc291c6ccf99 /test/ruby | |
| parent | a40645e115e6cd6328bb302dfc78b16f6ad45938 (diff) | |
merge revision(s) 2dd46bb82ffc4dff01d7ea70922f0e407acafb4e: [Backport #20468]
[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 cc332a9412..8c76f5cc28 100644 --- a/test/ruby/test_syntax.rb +++ b/test/ruby/test_syntax.rb @@ -1209,6 +1209,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") |
