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

Constant pattern vs governing type that is unconstrained type parameter #24550

Closed
gafter opened this issue Jan 31, 2018 · 2 comments
Closed

Constant pattern vs governing type that is unconstrained type parameter #24550

gafter opened this issue Jan 31, 2018 · 2 comments

Comments

@gafter
Copy link
Member

gafter commented Jan 31, 2018

The following in currently rejected:

    void M<T>(T t)
    {
        switch (t)
        {
            // Cannot implicitly converty type 'int' to 'T'
            case 3: break;
            // Cannot convert null to type parameter 'T' because it could be a non-nullable value type. Consider using 'default(T)' instead.
            case null: break;
        }
        // Cannot implicitly converty type 'int' to 'T'
        if (t is 3) { }
        // Cannot convert null to type parameter 'T' because it could be a non-nullable value type. Consider using 'default(T)' instead.
        if (t is null) { }
    }

However, these are perfectly reasonable pattern-matching operations. The spec and implementation should change to permit this.

@gafter
Copy link
Member Author

gafter commented Mar 19, 2018

This will be addressed in C# 8.0 with the change dotnet/csharplang#1284

@gafter
Copy link
Member Author

gafter commented Apr 12, 2018

Fixed in #25995

@gafter gafter closed this as completed Apr 12, 2018
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

1 participant