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

CS8619 Null forgiving operator and ternary operator ?: #40759

Open
FICTURE7 opened this issue Jan 6, 2020 · 1 comment
Open

CS8619 Null forgiving operator and ternary operator ?: #40759

FICTURE7 opened this issue Jan 6, 2020 · 1 comment

Comments

@FICTURE7
Copy link

FICTURE7 commented Jan 6, 2020

Version Used:
Visual Studio Community 2019 16.3.5

Steps to Reproduce:

  1. Use ternary operator with task whose result can be nullable as follows.
public Task<string?> ThingAsync(int x)
{
    var what0 = Task.FromResult("");
    var what1 = Task.FromResult(default(string));
    if (x == 0)
        return what0!; // No warning.
    return what1;
}

public Task<string?> ThingTernaryAsync(int x)
{
    var what0 = Task.FromResult("");
    var what1 = Task.FromResult(default(string));
    return x == 0 ? what0! : what1; // Warning.
}

Here is the SharpLab link.

Expected Behavior:
No warning in ThingTernaryAsync(int).

Actual Behavior:

Warning	CS8619	Nullability of reference types in value of type 'Task<string>' doesn't match target type 'Task<string?>'.
Warning	CS8619	Nullability of reference types in value of type 'Task<string?>' doesn't match target type 'Task<string>'.
@FICTURE7 FICTURE7 changed the title CS8619 False positive using ternary operator ?: CS8619 Null forgiving operator and ternary operator ?: Jan 6, 2020
@jcouv
Copy link
Member

jcouv commented Jan 7, 2020

FYI @cston

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Nullable Board
Suppression
Development

No branches or pull requests

2 participants