-
-
Notifications
You must be signed in to change notification settings - Fork 662
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
?.
Null-Safety Fails with match
Method on Enums
#11893
Comments
Since 46481f6 this gives an error. I don't know if this is worth supporting. My intuition is that |
Both |
Yes that's why this errors now to communicate that null-safety isn't supported by I'd actually be open to making the normal |
FWIW nullable enums actually work fine in
Well, dunno, given the above circumstances I would say:
|
Did you mean a |
Hmm, seems like the link I posted is wrong. So here's both I would say that these behaviors really quite consistent. I wouldn't want the compiler to insert null checks when I say that the value is non-null. I could imagine that on some targets that might actually box the enum before doing the null check, which adds even more overhead than just the null check itself. That being said, if the compiler supports |
The problem isn't the implementation but the specification. It's unclear to me if |
Welp, FWIW I think the current error is good enough ;) I guess what I'm saying is that the following suggestion doesn't seem like a good idea, because of the hidden runtime overhead (and additional generated code):
Still, let's say we would want to support it and for the sake of consistency, it would be |
To me there's a conflict between consistency and usefulness here because I'd consider a null-safe Then again it might not make much difference in any actual logic assuming that |
Description of the Issue
The
null-safety
behavior of the?.
operator does not work correctly when calling thematch
method on anull
value. This results in aTypeError: v is null
, even though the?.
operator is expected to prevent method calls onnull
.Minimal Reproducible Example (see here)
Expected Behavior
The
?.
operator should properly handlenull
values and avoid calling thematch
method when the value isnull
. For example, ifv = null
, the statementtrace(v?.match(Value1));
should evaluate tonull
without throwing an error.Actual Behavior
When
v?.match(Value1)
is called andv
isnull
, aTypeError: v is null
is thrown, breaking the expectednull-safety
behavior of the?.
operator.Environment
Additional Information
This issue violates the
null-safety
guarantees of the?.
operator, leading to unexpected runtime errors when relying on this functionality in code.The text was updated successfully, but these errors were encountered: