Project

General

Profile

Bug #10315

Override policy for duplicated keywords

Added by ko1 (Koichi Sasada) about 5 years ago. Updated about 5 years ago.

Status:
Closed
Priority:
Normal
Target version:
ruby -v:
2.2-2.0
[ruby-core:65368]

Description

p({k1: 'a', k1: 'b'})         #=> {:k1=>"b"}
p({k1: 'a'}.merge({k1: 'b'})) #=> {:k1=>"b"}
p(k1: 'a', k1: 'b')           #=> {:k1=>"b"}
p(k1: 'a', **{k1: 'b'})       #=> {:k1=>"a"}

IMO the last case should also output {:k1=>"b"}.

Nobu said that we should show warning for such duplication (especially for 1st and 3rd cases) because we can detect duplication while parsing/compiling.


Related issues

Related to Ruby master - Bug #11501: About priority of a hash element when using {**hash1, **hash2} literalClosedActions

Associated revisions

Revision 15716827
Added by nobu (Nobuyoshi Nakada) about 5 years ago

parse.y: precedence of duplicated keys

  • parse.y (assocs): concatenate splatted literal hashes. the former key has precedence even if duplicated literal keys follow. [ruby-core:65368] [Bug #10315]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47877 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 47877
Added by nobu (Nobuyoshi Nakada) about 5 years ago

parse.y: precedence of duplicated keys

  • parse.y (assocs): concatenate splatted literal hashes. the former key has precedence even if duplicated literal keys follow. [ruby-core:65368] [Bug #10315]

Revision 47877
Added by nobu (Nobuyoshi Nakada) about 5 years ago

parse.y: precedence of duplicated keys

  • parse.y (assocs): concatenate splatted literal hashes. the former key has precedence even if duplicated literal keys follow. [ruby-core:65368] [Bug #10315]

Revision 47877
Added by nobu (Nobuyoshi Nakada) about 5 years ago

parse.y: precedence of duplicated keys

  • parse.y (assocs): concatenate splatted literal hashes. the former key has precedence even if duplicated literal keys follow. [ruby-core:65368] [Bug #10315]

Revision 47877
Added by nobu (Nobuyoshi Nakada) about 5 years ago

parse.y: precedence of duplicated keys

  • parse.y (assocs): concatenate splatted literal hashes. the former key has precedence even if duplicated literal keys follow. [ruby-core:65368] [Bug #10315]

Revision 47877
Added by nobu (Nobuyoshi Nakada) about 5 years ago

parse.y: precedence of duplicated keys

  • parse.y (assocs): concatenate splatted literal hashes. the former key has precedence even if duplicated literal keys follow. [ruby-core:65368] [Bug #10315]

Revision 47877
Added by nobu (Nobuyoshi Nakada) about 5 years ago

parse.y: precedence of duplicated keys

  • parse.y (assocs): concatenate splatted literal hashes. the former key has precedence even if duplicated literal keys follow. [ruby-core:65368] [Bug #10315]

Revision 8771d1a0
Added by nobu (Nobuyoshi Nakada) about 5 years ago

vm.c: precedence of duplicated keys

  • vm.c (kwmerge_i): override existing keys by new keys. [ruby-core:65368] [Bug #10315]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47878 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 47878
Added by nobu (Nobuyoshi Nakada) about 5 years ago

vm.c: precedence of duplicated keys

  • vm.c (kwmerge_i): override existing keys by new keys. [ruby-core:65368] [Bug #10315]

Revision 47878
Added by nobu (Nobuyoshi Nakada) about 5 years ago

vm.c: precedence of duplicated keys

  • vm.c (kwmerge_i): override existing keys by new keys. [ruby-core:65368] [Bug #10315]

Revision 47878
Added by nobu (Nobuyoshi Nakada) about 5 years ago

vm.c: precedence of duplicated keys

  • vm.c (kwmerge_i): override existing keys by new keys. [ruby-core:65368] [Bug #10315]

Revision 47878
Added by nobu (Nobuyoshi Nakada) about 5 years ago

vm.c: precedence of duplicated keys

  • vm.c (kwmerge_i): override existing keys by new keys. [ruby-core:65368] [Bug #10315]

Revision 47878
Added by nobu (Nobuyoshi Nakada) about 5 years ago

vm.c: precedence of duplicated keys

  • vm.c (kwmerge_i): override existing keys by new keys. [ruby-core:65368] [Bug #10315]

Revision 47878
Added by nobu (Nobuyoshi Nakada) about 5 years ago

vm.c: precedence of duplicated keys

  • vm.c (kwmerge_i): override existing keys by new keys. [ruby-core:65368] [Bug #10315]

Revision 5fa4d562
Added by nobu (Nobuyoshi Nakada) about 5 years ago

parse.y: remove duplicate keys

  • parse.y (remove_duplicate_keys): remove duplicate literal keys, i.e., symbols and strings. [ruby-core:65368] [Bug #10315]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47879 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 47879
Added by nobu (Nobuyoshi Nakada) about 5 years ago

parse.y: remove duplicate keys

  • parse.y (remove_duplicate_keys): remove duplicate literal keys, i.e., symbols and strings. [ruby-core:65368] [Bug #10315]

Revision 47879
Added by nobu (Nobuyoshi Nakada) about 5 years ago

parse.y: remove duplicate keys

  • parse.y (remove_duplicate_keys): remove duplicate literal keys, i.e., symbols and strings. [ruby-core:65368] [Bug #10315]

Revision 47879
Added by nobu (Nobuyoshi Nakada) about 5 years ago

parse.y: remove duplicate keys

  • parse.y (remove_duplicate_keys): remove duplicate literal keys, i.e., symbols and strings. [ruby-core:65368] [Bug #10315]

Revision 47879
Added by nobu (Nobuyoshi Nakada) about 5 years ago

parse.y: remove duplicate keys

  • parse.y (remove_duplicate_keys): remove duplicate literal keys, i.e., symbols and strings. [ruby-core:65368] [Bug #10315]

Revision 47879
Added by nobu (Nobuyoshi Nakada) about 5 years ago

parse.y: remove duplicate keys

  • parse.y (remove_duplicate_keys): remove duplicate literal keys, i.e., symbols and strings. [ruby-core:65368] [Bug #10315]

Revision 47879
Added by nobu (Nobuyoshi Nakada) about 5 years ago

parse.y: remove duplicate keys

  • parse.y (remove_duplicate_keys): remove duplicate literal keys, i.e., symbols and strings. [ruby-core:65368] [Bug #10315]

Revision 37d0c873
Added by nobu (Nobuyoshi Nakada) about 5 years ago

parse.y: should not eliminate value nodes

  • parse.y (remove_duplicate_keys): should not simply eliminate all value nodes, which may have side effects. [ruby-core:65625] [Bug #10315]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47894 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 47894
Added by nobu (Nobuyoshi Nakada) about 5 years ago

parse.y: should not eliminate value nodes

  • parse.y (remove_duplicate_keys): should not simply eliminate all value nodes, which may have side effects. [ruby-core:65625] [Bug #10315]

Revision 47894
Added by nobu (Nobuyoshi Nakada) about 5 years ago

parse.y: should not eliminate value nodes

  • parse.y (remove_duplicate_keys): should not simply eliminate all value nodes, which may have side effects. [ruby-core:65625] [Bug #10315]

Revision 47894
Added by nobu (Nobuyoshi Nakada) about 5 years ago

parse.y: should not eliminate value nodes

  • parse.y (remove_duplicate_keys): should not simply eliminate all value nodes, which may have side effects. [ruby-core:65625] [Bug #10315]

Revision 47894
Added by nobu (Nobuyoshi Nakada) about 5 years ago

parse.y: should not eliminate value nodes

  • parse.y (remove_duplicate_keys): should not simply eliminate all value nodes, which may have side effects. [ruby-core:65625] [Bug #10315]

Revision 47894
Added by nobu (Nobuyoshi Nakada) about 5 years ago

parse.y: should not eliminate value nodes

  • parse.y (remove_duplicate_keys): should not simply eliminate all value nodes, which may have side effects. [ruby-core:65625] [Bug #10315]

Revision 47894
Added by nobu (Nobuyoshi Nakada) about 5 years ago

parse.y: should not eliminate value nodes

  • parse.y (remove_duplicate_keys): should not simply eliminate all value nodes, which may have side effects. [ruby-core:65625] [Bug #10315]

Revision 4a883ff9
Added by nobu (Nobuyoshi Nakada) about 5 years ago

parse.y: keep nodes linking

  • parse.y (remove_duplicate_keys): should keep nodes linking not to be collected. [Bug #10315]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47898 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 47898
Added by nobu (Nobuyoshi Nakada) about 5 years ago

parse.y: keep nodes linking

  • parse.y (remove_duplicate_keys): should keep nodes linking not to be collected. [Bug #10315]

Revision 47898
Added by nobu (Nobuyoshi Nakada) about 5 years ago

parse.y: keep nodes linking

  • parse.y (remove_duplicate_keys): should keep nodes linking not to be collected. [Bug #10315]

Revision 47898
Added by nobu (Nobuyoshi Nakada) about 5 years ago

parse.y: keep nodes linking

  • parse.y (remove_duplicate_keys): should keep nodes linking not to be collected. [Bug #10315]

Revision 47898
Added by nobu (Nobuyoshi Nakada) about 5 years ago

parse.y: keep nodes linking

  • parse.y (remove_duplicate_keys): should keep nodes linking not to be collected. [Bug #10315]

Revision 47898
Added by nobu (Nobuyoshi Nakada) about 5 years ago

parse.y: keep nodes linking

  • parse.y (remove_duplicate_keys): should keep nodes linking not to be collected. [Bug #10315]

Revision 47898
Added by nobu (Nobuyoshi Nakada) about 5 years ago

parse.y: keep nodes linking

  • parse.y (remove_duplicate_keys): should keep nodes linking not to be collected. [Bug #10315]

Revision 75c5b0af
Added by nagachika (Tomoyuki Chikanaga) almost 4 years ago

  • doc/NEWS-0.2.2: add description about incompatible change in Hash duplicated key overriding policy. [Bug #10315] [Bug #11501]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53050 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 53050
Added by nagachika (Tomoyuki Chikanaga) almost 4 years ago

  • doc/NEWS-0.2.2: add description about incompatible change in Hash duplicated key overriding policy. [Bug #10315] [Bug #11501]

Revision 53050
Added by nagachika (Tomoyuki Chikanaga) almost 4 years ago

  • doc/NEWS-0.2.2: add description about incompatible change in Hash duplicated key overriding policy. [Bug #10315] [Bug #11501]

Revision 53050
Added by nagachika (Tomoyuki Chikanaga) almost 4 years ago

  • doc/NEWS-0.2.2: add description about incompatible change in Hash duplicated key overriding policy. [Bug #10315] [Bug #11501]

Revision 53050
Added by nagachika (Tomoyuki Chikanaga) almost 4 years ago

  • doc/NEWS-0.2.2: add description about incompatible change in Hash duplicated key overriding policy. [Bug #10315] [Bug #11501]

Revision 53050
Added by nagachika (Tomoyuki Chikanaga) almost 4 years ago

  • doc/NEWS-0.2.2: add description about incompatible change in Hash duplicated key overriding policy. [Bug #10315] [Bug #11501]

Revision 4aeace73
Added by nagachika (Tomoyuki Chikanaga) almost 4 years ago

merge revision(s) 53050: [Backport #11501]

    * doc/NEWS-0.2.2: add description about incompatible change in Hash
      duplicated key overriding policy. [Bug #10315] [Bug #11501]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_2@53051 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 53051
Added by nagachika (Tomoyuki Chikanaga) almost 4 years ago

merge revision(s) 53050: [Backport #11501]

* doc/NEWS-0.2.2: add description about incompatible change in Hash
  duplicated key overriding policy. [Bug #10315] [Bug #11501]

History

Updated by nobu (Nobuyoshi Nakada) about 5 years ago

  • Status changed from Open to Closed
  • % Done changed from 0 to 100

Applied in changeset r47877.


parse.y: precedence of duplicated keys

  • parse.y (assocs): concatenate splatted literal hashes. the former key has precedence even if duplicated literal keys follow. [ruby-core:65368] [Bug #10315]

Updated by whitequark (whitequark *) about 5 years ago

Nobuyoshi Nakada wrote:

Applied in changeset r47877.


parse.y: precedence of duplicated keys

  • parse.y (assocs): concatenate splatted literal hashes. the former key has precedence even if duplicated literal keys follow. [ruby-core:65368] [Bug #10315]

There is a problem with this solution. Namely, duplicate key-value pairs are removed at parsing stage, and if they had side effects (like printing), the semantics changes.

For example:

p({k1: p('a'), k1: p('b')})         #=> {:k1=>"b"}
p({k1: p('a')}.merge({k1: p('b')})) #=> {:k1=>"b"}
p(k1: p('a'), k1: p('b'))           #=> {:k1=>"b"}
p(k1: p('a'), **{k1: p('b')})       #=> {:k1=>"a"}

In 2nd and 4th cases, 'a' and 'b' will be printed. In 1st and 3rd cases, only 'b' will be printed. This behavior is inconsistent.

#4

Updated by wanabe (_ wanabe) about 4 years ago

  • Related to Bug #11501: About priority of a hash element when using {**hash1, **hash2} literal added

Also available in: Atom PDF