Skip to content

False negative on nullable analysis #82550

@UniqeId6542

Description

@UniqeId6542

Version Used:
Visual Studio 18.1.1
C# Tools 5.0.0-2.25574.6

Steps to Reproduce:

internal class DoubleTryGetTest
{
    public static void Test()
    {
        if (TryGet1(out object? o))
        {
            string? s = o.ToString(); // null reference exception produced here.
        }
    }

    private static bool TryGet1([NotNullWhen(true)] out object? o)
    {
        return TryGet2(out o); // no warning
    }

    private static bool TryGet2(out object? o)
    {
        o = null;
        return true;
    }
}

Expected Behavior:
I expect CS8620 to be made somewhere in this code - likely in the body of TryGet1.

Actual Behavior:
No warning is made.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions