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

Remaining work for C# 9 pattern-matching changes #41502

Closed
17 of 18 tasks
gafter opened this issue Feb 7, 2020 · 4 comments
Closed
17 of 18 tasks

Remaining work for C# 9 pattern-matching changes #41502

gafter opened this issue Feb 7, 2020 · 4 comments

Comments

@gafter
Copy link
Member

gafter commented Feb 7, 2020

The following is the remaining work items not yet implemented for the C# 9 pattern-matching changes described in dotnet/csharplang#2850

Open Issues

  • What is the narrowed type for a for an or pattern? The current spec (common type) doesn't work as the common type permits representation-changing conversions (e.g. for int or long).
  • Is e is dynamic a "pure" null check? [See is dynamic should be treated as a "pure null" check #40960 ; not a pattern-matching issue]
@alrz
Copy link
Contributor

alrz commented Mar 18, 2020

What syntactic forms are permitted for an ITuple-based recursive pattern, and how would you write a single-element ITuple-based pattern? There is no way to do it currently.

To my surprise, both of these work already.

var x0 = obj is (int i) _;
var x1 = obj is var (x);

@gafter
Copy link
Member Author

gafter commented Mar 18, 2020

@alrz Then I have to make sure they continue to work.

@gafter
Copy link
Member Author

gafter commented Mar 20, 2020

@alrz I was concerned about this not working:

_ = o is (int) _;

This does not work because the right-hand-side is interpreted as a cast expression, which casts _ to the type int. You would have to write this

_ = o is (int _) _;

which does work.

@alrz
Copy link
Contributor

alrz commented Mar 20, 2020

FWIW, another way to disambiguate would be o is ((int)) _
Rare but this will also work if we had named constants: o is ((constant)) _

@gafter gafter closed this as completed May 4, 2020
@gafter gafter removed the 3 - Working label May 6, 2020
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

3 participants