diff options
author | Jeremy Evans <code@jeremyevans.net> | 2021-10-18 07:09:07 -0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-18 09:09:07 -0700 |
commit | fac2c0f73cafb5d65bfbba7aa8018fa427972d71 (patch) | |
tree | aacc9415ba64e1b2af30bc76c3ed92c620b1e940 /test/ruby/test_literal.rb | |
parent | 59bec48e48f7fc68a5bcff66642cceec0076e509 (diff) |
Fix evaluation order of hash values for duplicate keys
Fixes [Bug #17719]
Co-authored-by: Nobuyoshi Nakada <nobu@ruby-lang.org>
Co-authored-by: Ivo Anjo <ivo@ivoanjo.me>
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/4969
Merged-By: jeremyevans <code@jeremyevans.net>
Diffstat (limited to 'test/ruby/test_literal.rb')
-rw-r--r-- | test/ruby/test_literal.rb | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/test/ruby/test_literal.rb b/test/ruby/test_literal.rb index 3a8ff7857f..8c3256c034 100644 --- a/test/ruby/test_literal.rb +++ b/test/ruby/test_literal.rb @@ -474,6 +474,17 @@ class TestRubyLiteral < Test::Unit::TestCase assert_nil(h['c']) assert_equal(nil, h.key('300')) + a = [] + h = EnvUtil.suppress_warning do + eval <<~end + # This is a syntax that renders warning at very early stage. + # eval used to delay warning, to be suppressible by EnvUtil. + {"a" => a.push(100).last, "b" => a.push(200).last, "a" => a.push(300).last, "a" => a.push(400).last} + end + end + assert_equal({'a' => 400, 'b' => 200}, h) + assert_equal([100, 200, 300, 400], a) + assert_all_assertions_foreach( "duplicated literal key", ':foo', |