Skip to content

Pattern test should inform nullability #26745

@jcouv

Description

@jcouv

There should be no warning in the following, since s is string only matches if s isn't null.

using System;
public class C 
{
    public void M(string? s) 
    {
        if (s is string)
        {
            s.ToString(); // warning CS8602: Possible dereference of a null reference.
        }
    }
}

Conversely, s is null should also inform nullability.
Also, s = null!.

(update: split the null-coalesing issue into separate issue: #26747)

Once fixed, please update this speclet section.

Tagging @cston @gafter

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions