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

Nullable constraints not validated on tuple types inside method bodies #33303

Closed
jaredpar opened this issue Feb 11, 2019 · 0 comments · Fixed by #33336
Closed

Nullable constraints not validated on tuple types inside method bodies #33303

jaredpar opened this issue Feb 11, 2019 · 0 comments · Fixed by #33336
Assignees
Milestone

Comments

@jaredpar
Copy link
Member

Consider the following code:

#nullable enable

namespace System
{
    // struct with two values
    public struct ValueTuple<T1, T2>
        where T1 : object
        where T2 : object
    {
        public T1 Item1;
        public T2 Item2;

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

        public override string ToString()
        {
            return "";
        }
    }

}

class C {
    void M((string?, string) a) {
        string? s = null;
        var x = ("", s);
    }
}

The compiler will issue a warning for the tuple inside the method signature but not inside the method body.

@jaredpar jaredpar added this to the 16.1 milestone Feb 11, 2019
jaredpar added a commit to jaredpar/roslyn that referenced this issue Feb 12, 2019
This change enforces nullable validation on tuple type parameters,
assuming a custom defined tuple, inside of method bodies.

closes dotnet#33303
@jaredpar jaredpar self-assigned this Feb 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant