-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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
proposal: Go 2: on err { statement } and return! #33177
Comments
The fact an error variable is explicitly mentioned outside in the same line makes it not very similar I guess. That onErr is a bit too magical.
Yes, sure. The difference I proposed new keyword for such kind of returns, not the change of regular |
Also: #33029 |
The |
This is an anti-pattern: It's not backward compatible. Old code would suddenly no longer work, because |
file := os.Open(filename) or err {
log.Error().Err(err).Msg("file not found, fallback to stdin")
issue os.Stdin // file becomes os.Stdin if failed to open filename
}
I.e. this extended func Function(…) !(type₁, type₂, …, typeₙ) = func Function(…) (type₁, type₂, …, typeₙ, error) The implicit error except the case of func Function(…) error |
Example:
here
<vars> := A on <var> { … }
is an equivalent forwhere
<var>
must implement error.return!
is a shortcut for return statements with error. It substitutes first values with their type zeroes and the last value must be an error. Example:is an equivalent for
So, the first example is an equivalent for (inside the function returning
(*os.File, error)
)Pros:
on
, for instance. I mean this method will work with sum-types as well.Cons:
The text was updated successfully, but these errors were encountered: