Skip to content

Analyze tuple conversions element-wise with W-warnings #33035

@jcouv

Description

@jcouv

Currently, we treat tuples like generic Pair<T1, T2> during the conversion/assignment. This results in a redundant safety warning, since we already track the initial state of Item1/Item2 in the case of tuples.

image

#nullable enable
public class UnitTest1
{
    void M(string? s, string s2)
    {
        (string, string) t = (s, s2); // should be W-warning on elements
        t.Item1.ToString();

        // Motivations to change this:
        // - redundant safety warning
        // - generic type inference
        // - deconstruction

        Pair<string, string> p = Pair.Create(s, s2);
        p.Item1.ToString();

        var t2 = ((string, string))(s, s2); // should be W-warning on elements. t2 is (string, string), but state is Item1 is nullable 
        t2.Item1.ToString(); // safety
    }
}
public class Pair<T1, T2>
{
    public T1 Item1;
    public T2 Item2;
}
static class Pair
{
    public static Pair<T1, T2> Create<T1, T2>(T1 x, T2 y) { throw null; }
}

FYI @cston

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions