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

Pattern-matching changes for short tuples #30962

Closed
gafter opened this issue Nov 5, 2018 · 4 comments
Closed

Pattern-matching changes for short tuples #30962

gafter opened this issue Nov 5, 2018 · 4 comments
Assignees
Milestone

Comments

@gafter
Copy link
Member

gafter commented Nov 5, 2018

Adjust the implementation of pattern-matching to reflect LDM resolutions from 2018-11-05. The last point will be included in the changes for #20648.

Deconstruction vs ITuple

Proposed:

  1. If the type is a tuple type (any arity >=0; see below), then use the tuple semantics
  2. if the type has no accessible instance Deconstruct, and satisfies the ITuple deconstruct constraints, use ITuple semantics
  3. Otherwise attempt Deconstruct semantics (instance or extension)

Alternative

  1. If the type is a tuple type (any arity >= 0; see below), then use the tuple semantics
  2. If "binding" a Deconstruct invocation would finds one or more applicable methods, use Deconstruct.
  3. if the satisfies the ITuple deconstruct constraints, use ITuple semantics

In both cases, 4. Error

Decision: Alternative

Proposed:

  1. Permit pattern-matching tuple patterns with 0 and 1 elements (appropriately disambiguated as previously decided)
if (e is ()) ...

if (e is (1) _) ...
if (e is (x: 1)) ...

if (e is (1, 2)) ...

Conclusion: Approved

Proposed:

As part of this, I propose that we consider System.ValueTuple<T> instantitations to be considered tuple types. I do not propose any syntax changes related to this.

As part of this, I propose that we consider System.ValueTuple to be considered a tuple type. I do not propose any syntax changes related to this.

Conclusion: Approved

@gafter gafter added this to the 16.0 milestone Nov 5, 2018
@gafter gafter self-assigned this Nov 5, 2018
gafter added a commit to gafter/roslyn that referenced this issue Nov 7, 2018
Fixes dotnet#30962
Unfortunately we cannot test binding `var ()` and `var (x)` until dotnet#30935 has been integrated
gafter added a commit to gafter/roslyn that referenced this issue Nov 8, 2018
* Permit 0-element and 1-element tuple patterns
Fixes dotnet#30962
Replaces dotnet#31027

* Handle null and nullable input for a var pattern with a tuple designation
Fixes dotnet#30906
Replaces dotnet#30935

* Don't report missing Deconstruct when there is more than one applicable Deconstruct
Fixes dotnet#31031
@alrz
Copy link
Member

alrz commented Nov 15, 2018

if (e is (1) _) ...

Currently, (var x) would give you an error, so this doesn't really matter, but when we have parenthesized patterns, removing _ from something like (var x) _ would completely change the semantics, while variable designation is optional anywhere else in patterns in a sense that it would have no effect on the pattern itself. IMHO, it shouldn't be encouraged, or even supported?

@gafter
Copy link
Member Author

gafter commented Nov 15, 2018

IMHO, it shouldn't be encouraged, or even supported?

I don't understand what you are proposing should or should not be encouraged or supported.

@alrz
Copy link
Member

alrz commented Nov 15, 2018

I'm saying that it should not be encouraged, as in, not suggesting in the error message (from #31056).

and perhaps should not be supported at all, because of the confusion that it may create (later with the possible introduction of parenthesized patterns).

gafter pushed a commit that referenced this issue Nov 29, 2018
…31056)

* Permit the use of ITuple when Deconstruct exists but is ambiguous.

* Permit 0-element and 1-element tuple patterns
Fixes #30962
Replaces #31027

* Handle null and nullable input for a var pattern with a tuple designation
Fixes #30906
Replaces #30935

* Don't report missing Deconstruct when there is more than one applicable Deconstruct
Fixes #31031
@gafter
Copy link
Member Author

gafter commented Nov 29, 2018

Fixed in #31056

@gafter gafter closed this as completed Nov 30, 2018
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

2 participants