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 Enumerable#each block return type #10928

Conversation

straight-shoota
Copy link
Member

@straight-shoota straight-shoota commented Jul 13, 2021

The block's return type restriction should be empty instead of underscore (see #10467 (comment)). There's an unintended subtle difference for yielding blocks and underscore may break perfectly valid code (https://app.circleci.com/pipelines/github/straight-shoota/crinja/743/workflows/6a3278a5-8635-417a-96b5-ff7a483ae983/jobs/1307).

The block return type on Enumerable#each itself isn't really important because the block param type restriction is pretty much ignored for abstract defs (see #10902). But the type restriction on Iterator#each matters.

/cc #10905 (comment)

@straight-shoota straight-shoota added kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:stdlib:collection labels Jul 13, 2021
@straight-shoota straight-shoota added this to the 1.1.0 milestone Jul 13, 2021
Copy link
Member

@asterite asterite left a comment

Choose a reason for hiding this comment

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

An alternatively could be to remove the type restrictions.

@straight-shoota
Copy link
Member Author

straight-shoota commented Jul 13, 2021

Yes, I mentioned that in #10905 (comment)
But the type restriction on Iterator#each was added because it helps identify bugs. So I'd prefer to keep it. With nil return type, everything should be fine. 🤞

@straight-shoota
Copy link
Member Author

straight-shoota commented Jul 13, 2021

Despite #10933 being merged, I think this is still a good change because the output type of Enumerable#each's block is not used (see #10931 (comment)).

@straight-shoota straight-shoota removed this from the 1.1.0 milestone Jul 13, 2021
@straight-shoota straight-shoota added kind:docs kind:feature kind:bug A bug in the code. Does not apply to documentation, specs, etc. and removed kind:bug A bug in the code. Does not apply to documentation, specs, etc. kind:feature labels Jul 13, 2021
@straight-shoota straight-shoota added this to the 1.2.0 milestone Jul 22, 2021
@straight-shoota straight-shoota merged commit bcfc1e5 into crystal-lang:master Jul 25, 2021
@straight-shoota straight-shoota deleted the fix/enumerable-each-block-return branch July 25, 2021 15:53
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. kind:docs topic:stdlib:collection
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants