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.

Behavior with Nullable Interface while implicit maybe-generation

See original GitHub issue

Currently if facing in an issue / behavior with the implicit Maybe-generation. As for an example:

    public interface ITest
    {
        
    }

        private Maybe<ITest> CallMethod()
        {
            ITest? test = null;
            return test;
        }

The return test resulted in an error cannot convert expression ITest? to return type Maybe<ITest>. Is there not an implicit conversion for nullable interfaces? The above described problem is an easy example. In my code i receive (from Quartz.net) e.g. a Task<ITrigger?> and, also for async operations, the implicit conversion does not work.

Regards Laszlo

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
LaszloLueckcommented, Jul 14, 2021

Hi Vladimir, thanks for your response. I think you´re right. It is not the best idea to wrap an extension like maybe over a low level nullable handling like in c# 8.0 (which is exactly designed for). As i coded in Scala, there was the best practice to handle nulls as None<T> or not nulls as Some<T> to avoid nulls from your code.

I leave my function extensions to remove the nullables in my project. This is primarily syntactic sugar for me, to avoid the handling with ?? and ?.

Thanks for your patience,

Regards, Laszlo

0reactions
vkhorikovcommented, Jul 14, 2021

Sorry for late replies.

You can have it both ways:

Maybe<ITest> maybe = Maybe.From(test);

or

Maybe<ITest?> maybe = Maybe.From(test);

The compiler will agree with either option.

Your suggestion is to add extensions for T?, in addition to Maybe<T>? If so, I don’t think it’s a good idea, from the point of keeping the library focused on the one way of doing things. T? is an alternative to Maybe<T>. It makes sense to support the conversion from one to the other, but not re-implement the existing extension methods on top of both.

Read more comments on GitHub >

github_iconTop Results From Across the Web

What is the reason why nullable reference types defined in ...
Nullability is indicated by attributes, which aren't part of the method signature. In this case, it's applied to the interface (add void ...
Read more >
Nullable reference types
This article provides an overview of nullable reference types. You'll learn how the feature provides safety against null reference ...
Read more >
Resolve nullable warnings
This set of warnings alerts you that you're dereferencing a variable whose null-state is maybe-null. These warnings are:.
Read more >
Nullable differences in partial type base and interfaces #5107
Currently, the compiler doesn't have very coherent behavior when nullability differences are present across partial declarations.
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