Skip to content

Extract method drops nullable annotation on explicit cast #39075

@jasonmalinowski

Description

@jasonmalinowski

Copy into a C# 8.0 app:

#nullable enable

namespace ConsoleApp65
{
    class C
    {
        void M()
        {
            object? o = null;
            var s = (string?)o;
            Console.WriteLine(s);
        }
    }
}

Invoke extract method on the "o" in the "var s..." line. Do not select the cast, just the o.

Expected: the generated method returns string? because that's the explicit cast before it.
Actual: it returns just string which breaks code.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions