[ruby-core:102836] [Ruby master Bug#17719] Irregular evaluation order in hash literals
From:
xtkoba+ruby@...
Date:
2021-03-12 20:40:27 UTC
List:
ruby-core #102836
Issue #17719 has been updated by xtkoba (Tee KOBAYASHI).
To me the evaluation order of 1->3->2 is a bit unexpected, but it might be OK unless specified otherwise.
IMO, duplicate keys in hash literals should be allowed in a scripting language like Ruby. For example, they are explicitly allowed in another scripting language named Python [1]. On the other hand, compiled languages should disallow them.
[1] https://mail.python.org/pipermail/python-ideas/2019-March/055726.html
----------------------------------------
Bug #17719: Irregular evaluation order in hash literals
https://bugs.ruby-lang.org/issues/17719#change-90894
* Author: nobu (Nobuyoshi Nakada)
* Status: Open
* Priority: Normal
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN, 3.0: UNKNOWN
----------------------------------------
@mame pointed out an irregular evaluation order example.
```sh
$ ruby -e '{foo:p(1), bar:p(2), foo:p(3)}'
-e:1: warning: key :foo is duplicated and overwritten on line 1
1
3
2
```
It feels like a bug.
https://github.com/nobu/ruby/tree/duplicated-keys-order
Or, probably it would be better to turn into an error?
--
https://bugs.ruby-lang.org/
Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>