question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Maybe<T>.None == null returns false

See original GitHub issue

Consider the following:

Maybe<Class> maybeClassFromEmpty = null;
	
Console.WriteLine(maybeClassFromEmpty == null); // returns false

Considering that Maybe<T> implicitly converts null to Maybe<T>.None I’d expect comparing it with null to return true

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
hankovichcommented, Feb 18, 2021

@pfitoussi

Maybe is a struct, it would never be null

That’s not right in 100% cases. You’re right that value type could never be null, however value type can provide it’s own implemetation of == (which can return true).

Let me summarize:

MyStruct value = ...
var result = value == null; // can return true, depends on == operator
var result = value is null; // will never return true, calls object.ReferenceEquals(object, object) under the hood, i.e. calls ReferenceEquals((object)value, null) and boxed struct will never be null
0reactions
petre-ccommented, Feb 25, 2021

Thank you!

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - Why doesn't null evaluate to false?
A condition only accepts Boolean values, null does not have the type Boolean so it doesn't work there. As for the NULL example...
Read more >
Is it better to return NULL or empty values from functions ...
This is because I want the computation to terminate normally and tell me that the function I have requested is not defined on...
Read more >
'is null' returns false on null objects
This statement is always true. However "not null" UnityEngine. Objects can be "unusable" and they fake to be null to indicate that state....
Read more >
Null in Python: Understanding Python's NoneType Object
Understanding Null in Python. None is the value a function returns when there is no return statement in the function: >>>
Read more >
Attributes interpreted by the C# compiler: Nullable static ...
not-null: Static analysis determines that a variable has a non-null value. ... If the return value is false, the value of message is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found