dotnet / roslyn

The Roslyn .NET compiler provides C# and Visual Basic languages with rich code analysis APIs.
https://docs.microsoft.com/dotnet/csharp/roslyn-sdk/
MIT License
19.02k stars 4.03k forks source link

SemanticModel doesn't reflect nullability of types calculated by flow analysis. #29856

Open AlekseyTs opened 6 years ago

AlekseyTs commented 6 years ago
        [Fact]
        public void MethodWithGenericOutParameter()
        {
            CSharpCompilation c = CreateCompilation(new[] { @"
public class C
{
    public void Main(string? key)
    {
        Copy(key, out var s);
        s/*T:string?*/.ToString(); // warn
    }
    public static void Copy<T>(T key, out T value) => throw null;
}
", NonNullTypesTrue, NonNullTypesAttributesDefinition });

            VerifyOutVar(c, "string!"); // PROTOTYPE(NullableReferenceTypes): expecting string?
            c.VerifyTypes();
            c.VerifyDiagnostics(
                // (7,9): warning CS8602: Possible dereference of a null reference.
                //         s/*T:string?*/.ToString(); // warn
                Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "s").WithLocation(7, 9)
                );
        }
jcouv commented 6 years ago

Relates to https://github.com/dotnet/roslyn/issues/26198 (issue tracking public APIs)

333fred commented 5 years ago

Note: this is just for GetSymbolInfo. GetDeclaredSymbol on the SingleVariableDesignationSyntax will return the correct result after https://github.com/dotnet/roslyn/pull/37322 is merged.

RikkiGibson commented 5 years ago

@333fred is this issue still present?

333fred commented 5 years ago

For GetSymbolInfo

333fred commented 5 years ago

Remaining work is for 16.4 time frame.

333fred commented 5 years ago

The only thing outstanding here is local functions nested inside reinferred lambdas, and any symbols that said local function contains, including:

This work is targeted for post 16.4 currently, so I'm moving this out.