Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix key type restriction of Hash#merge block #9495

Merged

Conversation

makenowjust
Copy link
Contributor

The key type restriction of Hash#merge block is wrong. K (receiver's key type) is specified, but it yields L (argument's key type) value in fact. This type mismatch causes a problem when key type is difference. For instance, the following sample cannot work due to this bug.

foo = {1 => "foo"}
bar = {1 => "bar", "fizz" => "buzz"}

p foo.merge(bar) { |k, v1, v2| v1 + v2 }
# Error: argument #1 of yield expected to be Int32, not (Int32 | String)

This PR fixes this restriction type into L correctly.

@jhass
Copy link
Member

jhass commented Jun 17, 2020

Mmh, does it also fix

foo = {1 => "foo"}
bar = {"fizz" => "buzz"}

p foo.merge(bar) { |k, v1, v2| v1 + v2 }

EDIT: Nvm, it does :)

@straight-shoota straight-shoota added this to the 1.0.0 milestone Nov 21, 2020
@straight-shoota straight-shoota added kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:stdlib:collection labels Nov 21, 2020
@straight-shoota straight-shoota merged commit e74074f into crystal-lang:master Nov 24, 2020
@straight-shoota
Copy link
Member

Thank you @makenowjust

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:stdlib:collection
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants