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

Champion "pattern-matching with generics" (C# 7.1) #154

Open
4 of 5 tasks
gafter opened this issue Feb 20, 2017 · 16 comments
Open
4 of 5 tasks

Champion "pattern-matching with generics" (C# 7.1) #154

gafter opened this issue Feb 20, 2017 · 16 comments
Assignees
Labels
Implemented Needs ECMA Spec This feature has been implemented in C#, but still needs to be merged into the ECMA specification Proposal champion
Milestone

Comments

@gafter
Copy link
Member

gafter commented Feb 20, 2017

See dotnet/roslyn#16195 (comment)

@axel-habermaier
Copy link

This is a very surprising limitation. It severely limits the usefulness of pattern matching in generic code, making many of the changes I was hoping to make to my code base impossible.

@gafter
Copy link
Member Author

gafter commented Mar 12, 2017

@axel-habermaier cast the switch expression to object to work around this issue.

@alrz
Copy link
Member

alrz commented Mar 12, 2017

I think this is also related here (dotnet/roslyn#17746)

void M<T>(T o)
{
  if (o is X x)
   ;
}

Ideally, e is T x should be valid anywhere e is T is. (excluding nullables, of course)

@aluanhaddad
Copy link

@gafter thanks for the work around but I really would like to have this work. I had the exact same experience as @axel-habermaier and it was very frustrating especially as the error was the direct result of applying a built in Roslyn suggested refactoring inside the implementation of a pattern matching API I had written. I realize it's probably a bug in the analyzer but that really compounded the frustration since the match expression in VS 15 Preview had actually obviated the need for the API entirely.

@CyrusNajmabadi
Copy link
Member

CyrusNajmabadi commented Apr 1, 2017

@aluanhaddad We discussed this in the LDM, and we believe this is an issue that definitely should be addressed. @gafter's comment was more about what you could do in the meantime to unblock yourself. We'll hopefully get this addressed in a upcoming release of VS (hopefully the next one :)).

Note: we've hit this issue in our own code, so we definitely feel your pain and understand why you'd want this fixed :)

@aluanhaddad
Copy link

@CyrusNajmabadi Thank you. I'm really glad to hear that this is likely to be resolved soon. That is excellent news!

@CyrusNajmabadi
Copy link
Member

I'm really glad to hear that this is likely to be resolved soon.

Yup! Though note the standard caveats about not being able to guarantee anything, and the future may change blah blah blah. But i'm crossing my fingers that this smoothly slots into the 7.1 release.

@aluanhaddad
Copy link

aluanhaddad commented Apr 1, 2017

Though note the standard caveats about not being able to guarantee anything, and the future may change blah blah blah.

Indeed. Deadlines get missed. If that were a cardinal sin in our industry I probably wouldn't even have a job anymore.
EDIT: This remark was intended to be humorous and taken lightly.

gafter added a commit to gafter/roslyn that referenced this issue Apr 18, 2017
…ameters.

Fixes dotnet#16195
This is a language change for 7.1. See dotnet/csharplang#154.
Some tests may fail until dotnet#18756 is integrated.
gafter pushed a commit to gafter/csharplang that referenced this issue Apr 18, 2017
gafter added a commit that referenced this issue Apr 18, 2017
@gafter gafter removed the Proposal label Apr 18, 2017
@gafter
Copy link
Member Author

gafter commented Apr 18, 2017

I have added a proposal for this, and a PR exists for it in the Roslyn repo at dotnet/roslyn#18784.

@gafter gafter changed the title Champion "permit pattern match of expression of type T:base with type derived" Champion "pattern-matching with generics" Apr 18, 2017
gafter added a commit to dotnet/roslyn that referenced this issue May 8, 2017
@jcouv jcouv changed the title Champion "pattern-matching with generics" Champion "pattern-matching with generics" (C# 7.1) Jun 5, 2017
@shaggygi
Copy link
Contributor

@gafter @jcouv was this implemented in 7.1 and now suppose to work in VS 2017?

@gafter
Copy link
Member Author

gafter commented Aug 28, 2017

Yes

@orthoxerox
Copy link

Shouldn't it be closed, then?

@jcouv
Copy link
Member

jcouv commented Aug 28, 2017

There is a remaining workitem to update the language spec to reflect this feature. That's why the issue is kept open.

@shaggygi
Copy link
Contributor

Thank you for reply

@reinseth
Copy link

The link to the proposal in the description is broken. Should be https://github.com/dotnet/csharplang/blob/master/proposals/csharp-7.1/generics-pattern-match.md

@jcouv
Copy link
Member

jcouv commented May 14, 2018

@reinseth Fixed. Thanks

@333fred 333fred added the Implemented Needs ECMA Spec This feature has been implemented in C#, but still needs to be merged into the ECMA specification label Oct 16, 2020
@dotnet dotnet locked and limited conversation to collaborators Dec 26, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Implemented Needs ECMA Spec This feature has been implemented in C#, but still needs to be merged into the ECMA specification Proposal champion
Projects
None yet
Development

No branches or pull requests

10 participants