-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Allow Iterator.stop to be used inside Iterator.of block #4208
Conversation
|
||
private def self.without_stop(&block : -> T) | ||
e = block.call | ||
raise "" if e.is_a?(Iterator::Stop) |
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.
raise ArgumentError.new
?
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.
This method isn't called, only used for typeof.
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.
Oh, I see. Still, raise ""
(which internally translates to raise ArgumentError.new
, no?) looks odd for me...
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.
No, raise ""
= raise Exception.new
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.
So, why no raise Exception.new
? Seems imo clearer.
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.
We just need a function that returns NoReturn
. The same raise ""
pattern is used in https://github.com/crystal-lang/crystal/blob/master/src/iterator.cr#L472 .
The code is never executed actually.
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.
Fair 'nuff, I just thought it looks odd aside of its actual function.
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.
We could find probably a more idiomatic way to express this. maybe a fail : NoReturn
or halt
or unreachable
that will abort compilation at codegen but will return NoReturn
in semantic could work better. #someday
Ref #4198 (comment)
Before PR using
Iterator.stop
in the block given toIterator.of
would generate a union between the expected type andIterator::Stop
.