Skip to content

Improve nullable annotations for Result.Error#1

Open
3Matvey wants to merge 1 commit into
karanraj-tech:mainfrom
3Matvey:improve-nullable-result-error
Open

Improve nullable annotations for Result.Error#1
3Matvey wants to merge 1 commit into
karanraj-tech:mainfrom
3Matvey:improve-nullable-result-error

Conversation

@3Matvey
Copy link
Copy Markdown

@3Matvey 3Matvey commented May 6, 2026

This PR improves nullable flow analysis for the Result type.

Result already guarantees that Error is non-null when IsSuccess is false.
This change communicates that invariant to the compiler using
MemberNotNullWhen.

It also adds a null guard in the failure constructor to preserve the invariant
at runtime.

Before:

if (!result.IsSuccess)
    return result.Error!;

After:

if (!result.IsSuccess)
    return result.Error;

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

Successfully merging this pull request may close these issues.

1 participant