-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Update list-patterns.md #4982
Update list-patterns.md #4982
Conversation
proposals/list-patterns.md
Outdated
|
||
A *slice_pattern* without a subpattern is compatible with any type that is compatible with a *list_pattern*. | ||
|
||
A type is *countable* if it has an accessible property getter that returns an `int` and has the name `Length` or `Count`. If both properties are present, the former is preferred. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📝 This definition was removed in a previous PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need to add it back? Both concepts already exist via the C# features around range and index, I'm not sure we should duplicate here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reverted.
A couple of questions:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should iTuple switch { (1,2,3) => 1, [1,2,3] => 2, _ => 0 } produce an error? ITuple is both countable and indexable.
I don't see how it could, unless we wanted to make assumptions about general correspondence between positional pattern indexes and list pattern indexes. This doesn't seem like a necessarily-safe assumption to me.
In [..[1], 2] we only check length on the outer list (length=2) but we still check indexer values off of slice (if not subsumed by another test anywhere else). Is that ok?
Seems both find and desirable to me. That's what the pattern says should happen, so we should do it.
proposals/list-patterns.md
Outdated
|
||
A *slice_pattern* without a subpattern is compatible with any type that is compatible with a *list_pattern*. | ||
|
||
A type is *countable* if it has an accessible property getter that returns an `int` and has the name `Length` or `Count`. If both properties are present, the former is preferred. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need to add it back? Both concepts already exist via the C# features around range and index, I'm not sure we should duplicate here.
Because ITuple can be matched with both a list pattern and a positional pattern, the codegen would be identical. In fact, anything we specified for pattern compatibility here applies to ITuple, including the positive values for length. |
I'm unsure about this one. Let's assume this shouldn't produce an error for now, treating the positional and the list patterns as orthogonal.
Yes, that sounds good to me as well. This behaves the same as when the nested list-pattern has a designation. |
Only thing I'm missing from signing off is the answer to why we're adding back the definition of indexable and countable here. I don't think they need to be in this document. |
This is like mixing |
FYI, added a note to test plan to follow up on ITuple question. |
No description provided.