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

Record constructor arguments should propagate nullability to properties #44763

Open
RikkiGibson opened this issue Jun 1, 2020 · 2 comments
Open

Comments

@RikkiGibson
Copy link
Contributor

Version Used:
f36e10a

Steps to Reproduce:

#nullable enable
data class B(string? X, string? Y)
{
    static void M1(bool flag)
    {
        B b = new B(""hello"", null);
        if (flag)
        {
            b.X.ToString(); // shouldn't warn
            b.Y.ToString(); // 1
        }

        b = b with { Y = ""world"" };
        b.X.ToString(); // shouldn't warn
        b.Y.ToString();
    }
}

Expected Behavior:
Warning only on line // 1

Actual Behavior:
Warnings on line // 1 as well as // shouldn't warn lines

@RikkiGibson
Copy link
Contributor Author

The main blocker on this is that we don't have a decent way to tell if a constructor is the record primary constructor. We can in source, but not so easily in metadata. We could go forward by just assuming that every record constructor parameter assigns to an identically-named property, but this seems dubious.

@RikkiGibson
Copy link
Contributor Author

Solution to this issue should also address deconstruction as described in #49741

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

No branches or pull requests

4 participants