-
Notifications
You must be signed in to change notification settings - Fork 15
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
Comparing Option<T> to null doesn't work as expected #34
Comments
Looking at the code around the Time for a serious bit of refactoring... |
Accidentally checked in the fix for this with the commit of the 4th May. Comparisons between options, maybes and null are greatly simplified. |
Bug fix included in the v3.0.0 release. |
It's not as simple as it seems. SQL null comparison rules state that any comparison to null value returns It's not clear which null comparison standard is "true". |
How is that? Why do we care about SQL rules? In CLR world comparing one null reference to another null reference is determined to return "true" (https://github.com/dotnet/csharplang/blob/master/spec/types.md#the-bool-type).
|
Consider this code.
isNull
equalsfalse
due to some type conversion magic:Without the explicit type cast, compiler chooses
public static bool operator ==(Option<T> a, Maybe<T> b) => (object) a != null && a.EqualsMaybe(b);
overload for equality operator (Option{T}.cs)."Free"
null
is cast first toOption<string>
and then is wrapped intoMaybe<string>
.public static implicit operator Maybe<T>(Option<T> option) => new Maybe<T>(option);
(Maybe{T}.cs)Equality operator returns
false
since first operand isnull
.The text was updated successfully, but these errors were encountered: