[ruby-core:126499] [Ruby Bug#22264] Warning missing from parse.y hash literals
Issue #22264 has been reported by kddnewton (Kevin Newton). ---------------------------------------- Bug #22264: Warning missing from parse.y hash literals https://bugs.ruby-lang.org/issues/22264 * Author: kddnewton (Kevin Newton) * Status: Open * Backport: 3.3: UNKNOWN, 3.4: UNKNOWN, 4.0: UNKNOWN ---------------------------------------- $ ruby --parser=parse.y -cve '{**{}, a: 1, **{a: 2}}' ruby 4.1.0dev (2026-04-21T02:07:14Z aot be86d5704f) [arm64-darwin23] Syntax OK $ ruby --parser=parse.y -cve '{a: 1, **{a: 2}}' ruby 4.1.0dev (2026-04-21T02:07:14Z aot be86d5704f) [arm64-darwin23] -e:1: warning: key :a is duplicated and overwritten on line 1 Syntax OK -- https://bugs.ruby-lang.org/
Issue #22264 has been updated by jeremyevans0 (Jeremy Evans). I'm not sure whether it is desirable to warn for `{a: 1, **{a: 2}}`. I would guess that internally, this hits the same warning for `{a: 1, a: 2}` (which should warn), but for implementation details, it doesn't hit the warning for `{**{}, a: 1, **{a: 2}}`. I think we should only warn for keywords in the same hash, not keywords in a splatted hash, even if the splatted hash is a literal. For one, warnings are to help Ruby programmers, and `{a: 1, **{a: 2}}` is not something a typical Ruby programmer would write (while `{a: 1, a: 2}` is a fairly common mistake). There is no reason for a Ruby programmer to deliberately keyword splat a literal hash inside a another hash. ---------------------------------------- Bug #22264: Warning missing from parse.y hash literals https://bugs.ruby-lang.org/issues/22264#change-118659 * Author: kddnewton (Kevin Newton) * Status: Open * Backport: 3.3: UNKNOWN, 3.4: UNKNOWN, 4.0: UNKNOWN ---------------------------------------- $ ruby --parser=parse.y -cve '{**{}, a: 1, **{a: 2}}' ruby 4.1.0dev (2026-04-21T02:07:14Z aot be86d5704f) [arm64-darwin23] Syntax OK $ ruby --parser=parse.y -cve '{a: 1, **{a: 2}}' ruby 4.1.0dev (2026-04-21T02:07:14Z aot be86d5704f) [arm64-darwin23] -e:1: warning: key :a is duplicated and overwritten on line 1 Syntax OK -- https://bugs.ruby-lang.org/
Issue #22264 has been updated by nobu (Nobuyoshi Nakada). Backport changed from 3.3: UNKNOWN, 3.4: UNKNOWN, 4.0: UNKNOWN to 3.3: REQUIRED, 3.4: REQUIRED, 4.0: REQUIRED I agree with Jeremy's concern, but I think it should be discussed separately. As for this bug, it stems from an oversight when we allowed `**` to be placed in locations other than the end of a hash literal; it should be fixed simply by removing the condition “unless the first element is NULL” from `assocs : assocs ‘,’ assoc`. ---------------------------------------- Bug #22264: Warning missing from parse.y hash literals https://bugs.ruby-lang.org/issues/22264#change-118663 * Author: kddnewton (Kevin Newton) * Status: Open * Backport: 3.3: REQUIRED, 3.4: REQUIRED, 4.0: REQUIRED ---------------------------------------- $ ruby --parser=parse.y -cve '{**{}, a: 1, **{a: 2}}' ruby 4.1.0dev (2026-04-21T02:07:14Z aot be86d5704f) [arm64-darwin23] Syntax OK $ ruby --parser=parse.y -cve '{a: 1, **{a: 2}}' ruby 4.1.0dev (2026-04-21T02:07:14Z aot be86d5704f) [arm64-darwin23] -e:1: warning: key :a is duplicated and overwritten on line 1 Syntax OK -- https://bugs.ruby-lang.org/
Issue #22264 has been updated by k0kubun (Takashi Kokubun). Backport changed from 3.3: REQUIRED, 3.4: REQUIRED, 4.0: REQUIRED to 3.3: REQUIRED, 3.4: REQUIRED, 4.0: DONE ruby_4_0 commit:310533c5a207db00382cc764775ca91e06acb17c merged revision(s) commit:e5132b162737829f744b2b23908b9d08479db977. ---------------------------------------- Bug #22264: Warning missing from parse.y hash literals https://bugs.ruby-lang.org/issues/22264#change-119001 * Author: kddnewton (Kevin Newton) * Status: Closed * Backport: 3.3: REQUIRED, 3.4: REQUIRED, 4.0: DONE ---------------------------------------- $ ruby --parser=parse.y -cve '{**{}, a: 1, **{a: 2}}' ruby 4.1.0dev (2026-04-21T02:07:14Z aot be86d5704f) [arm64-darwin23] Syntax OK $ ruby --parser=parse.y -cve '{a: 1, **{a: 2}}' ruby 4.1.0dev (2026-04-21T02:07:14Z aot be86d5704f) [arm64-darwin23] -e:1: warning: key :a is duplicated and overwritten on line 1 Syntax OK -- https://bugs.ruby-lang.org/
Issue #22264 has been updated by nagachika (Tomoyuki Chikanaga). Backport changed from 3.3: REQUIRED, 3.4: REQUIRED, 4.0: DONE to 3.3: REQUIRED, 3.4: DONE, 4.0: DONE ruby_3_4 commit:72aa33a12683d7e351ca406a4cad45e5f1f98e26 merged revision(s) commit:e5132b162737829f744b2b23908b9d08479db977. ---------------------------------------- Bug #22264: Warning missing from parse.y hash literals https://bugs.ruby-lang.org/issues/22264#change-119102 * Author: kddnewton (Kevin Newton) * Status: Closed * Backport: 3.3: REQUIRED, 3.4: DONE, 4.0: DONE ---------------------------------------- $ ruby --parser=parse.y -cve '{**{}, a: 1, **{a: 2}}' ruby 4.1.0dev (2026-04-21T02:07:14Z aot be86d5704f) [arm64-darwin23] Syntax OK $ ruby --parser=parse.y -cve '{a: 1, **{a: 2}}' ruby 4.1.0dev (2026-04-21T02:07:14Z aot be86d5704f) [arm64-darwin23] -e:1: warning: key :a is duplicated and overwritten on line 1 Syntax OK -- https://bugs.ruby-lang.org/
participants (5)
-
jeremyevans0 (Jeremy Evans) -
k0kubun (Takashi Kokubun) -
kddnewton (Kevin Newton) -
nagachika (Tomoyuki Chikanaga) -
nobu (Nobuyoshi Nakada)