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

SuppresNullableWarningExpression on switch expressions' governing expressions should suppress CS8655 #43172

Open
TessenR opened this issue Apr 8, 2020 · 1 comment

Comments

@TessenR
Copy link

TessenR commented Apr 8, 2020

Version Used:

Branch master (10 Mar 2020)
Latest commit 441c154 by msftbot[bot]:
Merge pull request #42303 from CyrusNajmabadi/useCompoundParens

Support parenthesized expressions in use-compound-operator.

Steps to Reproduce:

Compile the following code:

using System;
#nullable enable
public class C {
    public void M(string? s) {
        _ = s! switch { {} => 1 };
        
    }
}

Expected Behavior:
No warnings. Suppressed expressions are considered not nullable in all other contexts so this switch's input should be considered not nullable

Actual Behavior:
warning CS8655: The switch expression does not handle some null inputs (it is not exhaustive). is reported

Notes
The current behavior makes it impossible to easily suppress the warning as the following doesn't work either: (s switch { {} => 1 })!

@gafter
Copy link
Member

gafter commented Apr 13, 2020

I believe this is by design. {} is considered a "pure" null check. Therefore, using it implies that you expect that the input might be null, and we take that into consideration to consider the input possibly null. If you want to handle all inputs, use a wildcard instead (e.g. var _ or _).

@gafter gafter self-assigned this Apr 13, 2020
@gafter gafter added this to the Backlog milestone Apr 14, 2020
@gafter gafter modified the milestones: Backlog, Compiler.Next Jul 2, 2020
@gafter gafter removed their assignment Sep 3, 2020
@jaredpar jaredpar modified the milestones: Compiler.Next, Backlog Sep 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Development

No branches or pull requests

4 participants