Skip to content

Relax enforcement of conditional attributes #44080

@jcouv

Description

@jcouv
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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Active/Investigating

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions