-
Notifications
You must be signed in to change notification settings - Fork 55
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
Use of type cast to ignore errors #489
Comments
I think our mindset was that the use of cast here is not to ignore the error but rather to assert confidence in the value being of that type, even though it may be of another. I don't think we want to lose that. |
We kinda used the following practice when it comes to type checking string|error result = getSomeStringOrError();
if (s is error) {
// handle error
}
string s = <string>result; This is to reduce the long if else ladders and improve the code readability. This example is a minimal one, but there are some complex cases. This may effect it. |
@ThisaruGuruge That one is #73 |
I think the rule should be that you "cannot cast away error", meaning that if there are errors in the type before the cast, there must be errors in the type after the cast. The before/after errors don't have to be the same: it's fine to cast to a more precise error. Note that the language already provides |
We decided we are ok with the proposal in #489 (comment) |
Given:
Both of these will compile:
This feels like silently ignoring the error. Another example is
With lax static typing, type of
j.x.y
isjson|error
, and the cast to<string>
results in the error being implicitly converted to a panic.This relates to #350, #487 and #488.
The text was updated successfully, but these errors were encountered: