-
-
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
Suggest next
when trying to break from captured block
#7406
Conversation
In general, this is probably a good feature. But I'm not sure if "use next" is the best advice. It's not always as simple as that, because |
@straight-shoota Right on! I was thinking about In general, I think we should improve all of our error messages to look a bit more like Elm, where they take a lot of time to explain what went wrong and suggestions with their explanations. |
What about sometimes linking to the docs?
|
Actually, why it's not possible to use |
@Sija def capture(&block)
block
end
def foo
# This break looks like it will exit foo, but that can't happen
block = capture { break }
puts 1
block
end
block = foo
block.call |
I hope this is clear enough now. I don't think it needs to be as long as I proposed. In the end it might rather confuse the user. |
Indeed, that is way to long and too much detail. A simple "Maybe you can use |
@asterite Now it makes sense, thanks for explanation! |
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.
Thank you @r00ster91 👍
* 'master' of github.com:crystal-lang/crystal: Change the font-weight used in Playground (crystal-lang#7552) Fix formatting absolute paths (crystal-lang#7560) Refactor IO::Syscall as IO::Evented (crystal-lang#7505) YAML: fix test checking serialization of slices for libyaml 0.2.2 (crystal-lang#7555) Let Array#sort only use `<=>`, and let `<=>` return `nil` for partial comparability (crystal-lang#6611) Update `to_s` and `inspect` to have similar signatures accross the stdlib (crystal-lang#7528) Fix restriction of valid type vs free vars (crystal-lang#7536) Rewrite macro spec without executing a shell command (crystal-lang#6962) Suggest `next` when trying to break from captured block (crystal-lang#7406) Fix GenericClassType vs GenericClassInstanceType restrictions (crystal-lang#7537) Add human readable formatting for numbers (crystal-lang#6314) Add command and args to execvp error message (crystal-lang#7511) Implement Set#add? method (crystal-lang#7495)
When doing this:
then you get
Error in line 6: can't break from captured block
.Now this makes the error message suggest
next
because when usingbreak
in a captured block you most likely tried to escape from the captured block andnext
makes that possible.Also when you instead try to
return
from a captured block, it gives you a helpful error message:Error in line 6: can't return from captured block, use next
so why not suggestnext
in case ofbreak
too?This also downcases
next
's andbreak
's error message just like all the other error messages.