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

The is pattern matching on constraint type #20672

Closed
Meir017 opened this issue Jul 6, 2017 · 1 comment
Closed

The is pattern matching on constraint type #20672

Meir017 opened this issue Jul 6, 2017 · 1 comment
Labels
Resolution-Duplicate The described behavior is tracked in another issue

Comments

@Meir017
Copy link
Contributor

Meir017 commented Jul 6, 2017

Version Used:
Visual Studio 2017
Version 15.2 (26430.14) Release

Steps to Reproduce:
The following code works:

public class Person { }
public class Parent : Person { }
public class Program
{
    public static void Test<TPerson>(TPerson person) where TPerson : Person
    {
        if(person is Parent)
        {
             var parent = person as Parent;
        }
    }
}

The following code raises an error An expression of type TPerson cannot be handled by a pattern of type Parent:

public class Person { }
public class Parent : Person { }
public class Program
{
    public static void Test<TPerson>(TPerson person) where TPerson : Person
    {
        if(person is Parent parent)
        {
        }
    }
}
@sharwell
Copy link
Member

sharwell commented Jul 6, 2017

This looks like a duplicate of #16195. It is my understanding that the restriction on this use case was removed as part of the work on C# 7.1 (which ships with version 15.3).

@sharwell sharwell closed this as completed Jul 6, 2017
@sharwell sharwell added the Resolution-Duplicate The described behavior is tracked in another issue label Jul 6, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution-Duplicate The described behavior is tracked in another issue
Projects
None yet
Development

No branches or pull requests

2 participants