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.08k stars 4.04k forks source link

Unexpected warning CS0649: Field '(T1, T2).F1' is never assigned to #43588

Open AlekseyTs opened 4 years ago

AlekseyTs commented 4 years ago
namespace System
{
    // struct with two values
    public struct ValueTuple<T1, T2>
    {
        private static int F1 = 123;
        public T1 Item1;
        public T2 Item2;

        public ValueTuple(T1 item1, T2 item2)
        {
            this.Item1 = item1;
            this.Item2 = item2;
        }

        public override string ToString()
        {
            return F1.ToString();
        }
    }
}

Observed:

(6,28): warning CS0649: Field '(T1, T2).F1' is never assigned to, and will always have its default value 0

Expected: No warning, there is an initializer for the field.

AlekseyTs commented 4 years ago

cc @jcouv