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

Relax enforcement of conditional attributes #44080

Closed
jcouv opened this issue May 8, 2020 · 1 comment · Fixed by #46201
Closed

Relax enforcement of conditional attributes #44080

jcouv opened this issue May 8, 2020 · 1 comment · Fixed by #46201

Comments

@jcouv
Copy link
Member

jcouv commented May 8, 2020

class C<T>
{
    bool Method([MaybeNullWhen(false)] out T value)
    {
        ...
        return someBoolLocal; // will warn and is hard to suppress
    }
}

Should we relax the enforcement (since we don't track bool locals), or should we offer a way of suppressing?

Relates to dotnet/runtime#36104 (comment)

Options so far:

  1. assertions don’t work as far as I can tell
    Even making the two explicit branches of the return explicit with an if (someBoolLocal) { someAssertion(); return true; } else { return false; } there are no good assertions that resolve this.

  2. suppression with !
    You could bang all the assignments to value. Seems smelly though

  3. explicit suppression
    #pragma warning disable CS8762

  4. allow silencing the return statement
    return someBoolLocal !;.

  5. Only warn when we know the value of someBoolLocal.

@jcouv
Copy link
Member Author

jcouv commented Jun 3, 2020

We'll go with option 5

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

Successfully merging a pull request may close this issue.

2 participants