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

Update list-patterns.md #4982

Merged
merged 11 commits into from
Aug 3, 2021
Merged

Update list-patterns.md #4982

merged 11 commits into from
Aug 3, 2021

Conversation

alrz
Copy link
Member

@alrz alrz commented Jul 30, 2021

No description provided.

@alrz alrz requested a review from a team as a code owner July 30, 2021 07:26

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.
Copy link
Member Author

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.

Copy link
Member

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverted.

@alrz
Copy link
Member Author

alrz commented Aug 1, 2021

A couple of questions:

  • Should iTuple switch { (1,2,3) => 1, [1,2,3] => 2, _ => 0 } produce an error? ITuple is both countable and indexable.
  • 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?

Copy link
Member

@333fred 333fred left a 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.


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.
Copy link
Member

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.

@alrz
Copy link
Member Author

alrz commented Aug 2, 2021

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

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.

@jcouv
Copy link
Member

jcouv commented Aug 2, 2021

Should iTuple switch { (1,2,3) => 1, [1,2,3] => 2, _ => 0 } produce an error? ITuple is both countable and indexable.

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.
We can bring up to LDM when back in session (in 3 weeks).

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?

Yes, that sounds good to me as well. This behaves the same as when the nested list-pattern has a designation.

@333fred
Copy link
Member

333fred commented Aug 2, 2021

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.

@alrz
Copy link
Member Author

alrz commented Aug 3, 2021

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.

This is like mixing {Length:N} and list patterns. The result is the same across all pattern forms.

@333fred 333fred merged commit 2c0481f into dotnet:main Aug 3, 2021
@jcouv
Copy link
Member

jcouv commented Aug 3, 2021

FYI, added a note to test plan to follow up on ITuple question.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants