ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:102831] [Ruby master Bug#17719] Irregular evaluation order in hash literals
@ 2021-03-12 13:05 nobu
  2021-03-12 20:40 ` [ruby-core:102836] " xtkoba+ruby
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: nobu @ 2021-03-12 13:05 UTC (permalink / raw)
  To: ruby-core

Issue #17719 has been reported by nobu (Nobuyoshi Nakada).

----------------------------------------
Bug #17719: Irregular evaluation order in hash literals
https://bugs.ruby-lang.org/issues/17719

* 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/

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [ruby-core:102836] [Ruby master Bug#17719] Irregular evaluation order in hash literals
  2021-03-12 13:05 [ruby-core:102831] [Ruby master Bug#17719] Irregular evaluation order in hash literals nobu
@ 2021-03-12 20:40 ` xtkoba+ruby
  2021-07-15  6:22 ` [ruby-core:104611] " nobu
  2021-10-14 22:55 ` [ruby-core:105636] " jeremyevans0 (Jeremy Evans)
  2 siblings, 0 replies; 4+ messages in thread
From: xtkoba+ruby @ 2021-03-12 20:40 UTC (permalink / raw)
  To: ruby-core

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/

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [ruby-core:104611] [Ruby master Bug#17719] Irregular evaluation order in hash literals
  2021-03-12 13:05 [ruby-core:102831] [Ruby master Bug#17719] Irregular evaluation order in hash literals nobu
  2021-03-12 20:40 ` [ruby-core:102836] " xtkoba+ruby
@ 2021-07-15  6:22 ` nobu
  2021-10-14 22:55 ` [ruby-core:105636] " jeremyevans0 (Jeremy Evans)
  2 siblings, 0 replies; 4+ messages in thread
From: nobu @ 2021-07-15  6:22 UTC (permalink / raw)
  To: ruby-core

Issue #17719 has been updated by nobu (Nobuyoshi Nakada).


I think it can be fixed by removing the optimization in the parser and leaving it to the compiler.

----------------------------------------
Bug #17719: Irregular evaluation order in hash literals
https://bugs.ruby-lang.org/issues/17719#change-92898

* 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/

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [ruby-core:105636] [Ruby master Bug#17719] Irregular evaluation order in hash literals
  2021-03-12 13:05 [ruby-core:102831] [Ruby master Bug#17719] Irregular evaluation order in hash literals nobu
  2021-03-12 20:40 ` [ruby-core:102836] " xtkoba+ruby
  2021-07-15  6:22 ` [ruby-core:104611] " nobu
@ 2021-10-14 22:55 ` jeremyevans0 (Jeremy Evans)
  2 siblings, 0 replies; 4+ messages in thread
From: jeremyevans0 (Jeremy Evans) @ 2021-10-14 22:55 UTC (permalink / raw)
  To: ruby-core

Issue #17719 has been updated by jeremyevans0 (Jeremy Evans).


nobu (Nobuyoshi Nakada) wrote in #note-2:
> I think it can be fixed by removing the optimization in the parser and leaving it to the compiler.

I tried the approach of removing the optimization from the parser completely (https://github.com/jeremyevans/ruby/commit/bead10831e4f7ea6fc517fe66796f12579915fb3), but it doesn't handle duplicate keys in keyword arguments, resulting in incorrect unknown keyword errors: https://github.com/jeremyevans/ruby/runs/3900240357#step:15:168

I also tried rebasing your `duplicated-keys-order` branch against master, and that appears to fix the issue. I submitted a pull request for that: https://github.com/ruby/ruby/pull/4969

----------------------------------------
Bug #17719: Irregular evaluation order in hash literals
https://bugs.ruby-lang.org/issues/17719#change-94126

* 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/

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-10-14 22:56 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-12 13:05 [ruby-core:102831] [Ruby master Bug#17719] Irregular evaluation order in hash literals nobu
2021-03-12 20:40 ` [ruby-core:102836] " xtkoba+ruby
2021-07-15  6:22 ` [ruby-core:104611] " nobu
2021-10-14 22:55 ` [ruby-core:105636] " jeremyevans0 (Jeremy Evans)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).