-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Add and improve type restrictions of block arguments #10467
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
Merged
straight-shoota
merged 12 commits into
crystal-lang:master
from
straight-shoota:feature/improve-block-type-restrictions
Sep 21, 2021
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
0c78a86
Add and improve type restrictions of block arguments
straight-shoota 2cc0df7
Add Tuple
straight-shoota 2cdf53f
Merge branch 'master' into feature/improve-block-type-restrictions
straight-shoota b45db70
Merge branch 'master' into feature/improve-block-type-restrictions
straight-shoota ec3260f
Merge branch 'master' into feature/improve-block-type-restrictions
straight-shoota a828a46
Merge branch 'master' into feature/improve-block-type-restrictions
straight-shoota a7805f4
Fix return type in Indexable specs
straight-shoota b59ab63
Fixup
straight-shoota e7822da
Update src/array.cr
straight-shoota b22f1fb
Merge branch 'master' into feature/improve-block-type-restrictions
straight-shoota 493db85
Revert changes to #sort methods
straight-shoota d06943b
Merge branch 'master' into feature/improve-block-type-restrictions
straight-shoota File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason this and like
reject(!)shouldn't be forced to return aBool?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would definitely be a breaking change (so should be brought up in a different issue). Right now, the value just needs to be interpreted as truthy. And I think that's probably good. No need to force users to a bool conversion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't
T ->meanNilreturn value type?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope. It means there's no restriction on the return type. Basically like a free var.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think @Sija is right. You need to use underscore to mean any type
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's equivalent to
T -> _, which means "allow any return type".EDIT: Oops, didn't refresh 😬.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it's different for captured blocks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally we should probably improve the semantics, maybe make empty invalid for non-captured blocks and require an underscore since that's more explicit and fits with the use of underscore in the type grammar.
But for now, it's better to use empty because it's not entirely equivalent to underscore: https://forum.crystal-lang.org/t/difference-between-underscore-and-empty-as-block-return-value/2998
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See #10932 for the underscore issue and #10931 for a discussion about the intended semantics.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on #11210 we never constrain the return type to
Boolin contexts like this.