Skip to content

Fix duplicate keys in hash literals#15843

Merged
straight-shoota merged 2 commits intocrystal-lang:masterfrom
straight-shoota:spec/duplicate-hash-keys
May 30, 2025
Merged

Fix duplicate keys in hash literals#15843
straight-shoota merged 2 commits intocrystal-lang:masterfrom
straight-shoota:spec/duplicate-hash-keys

Conversation

@straight-shoota
Copy link
Member

This was discovered with ameba's Lint/HashDuplicatedKey rule.


it "works with mixed types" do
{1 => "a", "a" => 1, 2.0 => "a", "a" => 1.0}.values_at(1, "a", 2.0, "a").should eq({"a", 1, "a", 1.0})
{1 => "a", "a" => 1, 2.0 => "a", "b" => 1.0}.values_at(1, "a", 2.0, "a").should eq({"a", 1, "a", 1.0})
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thought: We're asking for the value of "a" twice, which happens to be 1 and equal to 1.0. Shall we ask for the value at "b" instead?

@straight-shoota straight-shoota added this to the 1.17.0 milestone May 28, 2025
@straight-shoota straight-shoota merged commit b677e0b into crystal-lang:master May 30, 2025
36 checks passed
@straight-shoota straight-shoota deleted the spec/duplicate-hash-keys branch May 30, 2025 10:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants