Skip to content
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

Handling of Nullables #119

Open
janschreieradac opened this issue Sep 27, 2024 · 0 comments
Open

Handling of Nullables #119

janschreieradac opened this issue Sep 27, 2024 · 0 comments

Comments

@janschreieradac
Copy link

Hi Amichai,

prior to the change of disallowing nullables this code worked fine:

  public static ErrorOr<Inspektionsvertrag?> TryCreateOrNull(int? freikilometer, int? freimonate)
    {
        if (freimonate is null or 0 && freikilometer is null or 0)
        {
            return  (Inspektionsvertrag?)null; //this used to work
        }
     ...

now I get the Argument-Null-Exception. So in my Use-Case not having values at all is fine and should not be an error.

A second issue realted to the same topic is a method with the following signature

 public static ErrorOr<Laufleistungslinie> TryCreate(int? a, int? b,  ErrorOr<Vorbesitzer>? vorbesitzer = null) 

prior to the change could be called with null as third parameter

var laufleistungslinie = Laufleistungslinie.TryCreate(20, 20, null);

this now also does a cast (although the whole errorOr<> is nullable, not only the T) and then throws null.

I would assume that being able to use nullables either on ErrorOr? or ErrorOr<T?> should be supported, but disallowing both is a bit too strict.

Hope my examples clarify my point. if not, please let me know

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant