Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Track nullable state for tuple items #29970

Closed
AlekseyTs opened this issue Sep 17, 2018 · 0 comments
Closed

Track nullable state for tuple items #29970

AlekseyTs opened this issue Sep 17, 2018 · 0 comments

Comments

@AlekseyTs
Copy link
Contributor

AlekseyTs commented Sep 17, 2018

        [Fact]
        public void TupleTypeInference_06()
        {
            var source =
@"class C
{
    static void F(object? x, object? y)
    {
        if (y != null)
        {
            ((object? x, object? y), object? z) t = ((x, y), y);
            t.Item1.Item1.ToString();
            t.Item1.Item2.ToString();
            t.Item2.ToString();
            t.Item1.x.ToString();
            t.Item1.y.ToString();
            t.z.ToString();
        }
    }
}";
            var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition });
            // PROTOTYPE(NullableReferenceTypes): Should not report warning for
            // `t.Item1.Item2`, `t.Item2`, `t.Item1.y`, or `t.z`.
            comp.VerifyDiagnostics(
                // (8,13): warning CS8602: Possible dereference of a null reference.
                //             t.Item1.Item1.ToString();
                Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "t.Item1.Item1").WithLocation(8, 13),
                // (9,13): warning CS8602: Possible dereference of a null reference.
                //             t.Item1.Item2.ToString();
                Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "t.Item1.Item2").WithLocation(9, 13),
                // (10,13): warning CS8602: Possible dereference of a null reference.
                //             t.Item2.ToString();
                Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "t.Item2").WithLocation(10, 13),
                // (11,13): warning CS8602: Possible dereference of a null reference.
                //             t.Item1.x.ToString();
                Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "t.Item1.x").WithLocation(11, 13),
                // (12,13): warning CS8602: Possible dereference of a null reference.
                //             t.Item1.y.ToString();
                Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "t.Item1.y").WithLocation(12, 13),
                // (13,13): warning CS8602: Possible dereference of a null reference.
                //             t.z.ToString();
                Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "t.z").WithLocation(13, 13));
        }

Related to #29699 (should conversion warnings be reported on elements or the whole tuple?)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants