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

Allow Iterator.stop to be used inside Iterator.of block #4208

Merged
merged 1 commit into from Apr 3, 2017

Conversation

bcardiff
Copy link
Member

Ref #4198 (comment)

Before PR using Iterator.stop in the block given to Iterator.of would generate a union between the expected type and Iterator::Stop.


private def self.without_stop(&block : -> T)
e = block.call
raise "" if e.is_a?(Iterator::Stop)
Copy link
Contributor

Choose a reason for hiding this comment

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

raise ArgumentError.new?

Copy link
Contributor

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.

Copy link
Contributor

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...

Copy link
Contributor

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

Copy link
Contributor

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.

Copy link
Member Author

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.

Copy link
Contributor

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.

Copy link
Member Author

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

@bcardiff bcardiff merged commit 0fbe4c8 into master Apr 3, 2017
@bcardiff bcardiff added this to the Next milestone Apr 3, 2017
@asterite asterite deleted the fix/iterator-of-stop branch April 27, 2018 21:12
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.

None yet

3 participants