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 pattern spec for narrowed type of ITuple pattern #3891

Merged
merged 2 commits into from
Sep 16, 2020

Conversation

gafter
Copy link
Member

@gafter gafter commented Sep 14, 2020

@gafter gafter requested a review from RikkiGibson September 14, 2020 18:30
@gafter gafter self-assigned this Sep 14, 2020
6. If `P` is an `or` pattern, the *narrowed type* is the common type of the *narrowed type* of the subpatterns if such a common type exists. For this purpose, the common type algorithm considers only identity, boxing, and implicit reference conversions, and it considers all subpatterns of a sequence of `or` patterns (ignoring parenthesized patterns).
7. If `P` is an `and` pattern, the *narrowed type* is the *narrowed type* of the right pattern. Moreover, the *narrowed type* of the left pattern is the *input type* of the right pattern.
8. Otherwise the *narrowed type* of `P` is `P`'s input type.
4. If `P` is [matched via the rules for](https://github.com/dotnet/csharplang/blob/master/proposals/csharp-8.0/patterns.md#positional-pattern) `ITuple`, the *narrowed type* is the type `System.ITuple`.
Copy link
Member

@alrz alrz Sep 15, 2020

Choose a reason for hiding this comment

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

Event if the input type is not ITuple itself, rather a compatible one?

interface IMyTuple : ITuple { object Foo { get; } }

obj is IMyTuple and (1, 2) and { Foo: null } // Foo is not recognized?

Copy link
Member

Choose a reason for hiding this comment

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

Confirmed we indeed get an error. two first patterns should be swapped for this to work.

Copy link
Member Author

Choose a reason for hiding this comment

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

@gafter gafter merged commit fcf884f into dotnet:master Sep 16, 2020
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.

Spec for patterns does not define the narrowed type for an ITuple-based pattern
3 participants