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

Nullability should be inferred from deconstruction #29618

Closed
cston opened this issue Aug 31, 2018 · 0 comments
Closed

Nullability should be inferred from deconstruction #29618

cston opened this issue Aug 31, 2018 · 0 comments
Assignees
Milestone

Comments

@cston
Copy link
Member

cston commented Aug 31, 2018

using System.Runtime.CompilerServices;
[NonNullTypes]
class C
{
    static (string?, string) F()
    {
        return (string.Empty, string.Empty);
    }
    void Deconstruct(out string? x, out string y)
    {
        x = string.Empty;
        y = string.Empty;
    }
    static void M()
    {
        (var x, var y) = new C();
        x.ToString(); // warning: maybe null
        y.ToString();
        (var z, var w) = F();
        z.ToString(); // warning: maybe null
        w.ToString();
    }
}

(jcouv update:)
Note: I've added references to this issue to replace PROTOTYPE markers. I believe that once the deconstruction scenario is properly handled, it should be possible to remove the following two methods:

        // PROTOTYPE(NullableReferenceTypes): Remove this method. Initial binding should not infer nullability.
        internal static TypeSymbolWithAnnotations GetTypeAndNullability(this BoundExpression expr)
        {
...
        }

        // PROTOTYPE(NullableReferenceTypes): Remove this method. Initial binding should not infer nullability.
        private static bool? IsNullableInternal(this BoundExpression expr)
        {
...
      
        }

As part of this, we should also review NullableWalker.VisitForEachIterationVariables.

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

2 participants