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 ref-struct-interfaces.md #8024

Merged
merged 13 commits into from
Apr 8, 2024
Merged

Update ref-struct-interfaces.md #8024

merged 13 commits into from
Apr 8, 2024

Conversation

AlekseyTs
Copy link
Contributor

No description provided.

```

A `using` statement will recognize and use implementation of `IAsyncDisposable` interface when resource is a type parameter that
`allows ref strict`, there is no `DisposeAsync` pattern match, and `IAsyncDisposable` is in type parameter's effective interfaces set.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
`allows ref strict`, there is no `DisposeAsync` pattern match, and `IAsyncDisposable` is in type parameter's effective interfaces set.
`allows ref struct`, there is no `DisposeAsync` pattern match, and `IAsyncDisposable` is in type parameter's effective interfaces set.

Copy link
Member

Choose a reason for hiding this comment

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

A using statement will recognize and use implementation of IAsyncDisposable interface when resource is a type parameter that
allows ref strict, there is no DisposeAsync pattern match, and IAsyncDisposable is in type parameter's effective interfaces set.

Currently, it looks like we use IAsyncDisposable even if there is a DisposeAsync pattern (available through an interface) - see sharplab.io.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

A using statement will recognize and use implementation of IAsyncDisposable interface when resource is a type parameter that
allows ref strict, there is no DisposeAsync pattern match, and IAsyncDisposable is in type parameter's effective interfaces set.

Currently, it looks like we use IAsyncDisposable even if there is a DisposeAsync pattern (available through an interface) - see sharplab.io.

I can see how this could be confusing, but there is no pattern match in this case due to an ambiguity.

Copy link
Member

@cston cston Apr 2, 2024

Choose a reason for hiding this comment

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

My comment here (and below) was about the text rather than the example. The text seems to state we'll use the interface implementation when there is no pattern implementation, which might imply that if there was a pattern implementation, we'd use the pattern implementation instead. But currently it looks like we use the interface implementation regardless of whether there is a pattern implementation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

there is no DisposeAsync pattern match

The statement doesn't talk about " a pattern implementation" there, it talks about "a pattern match", which doesn't have to exists (and in fact doesn't in some scenarios) when there is a pattern implementation.

```

A `foreach` statement will recognize and use implementation of ```IEnumerable<T>```/```IEnumerable``` interface when collection is a type parameter that
`allows ref strict`, there is no `GetEnumerator` pattern match, and ```IEnumerable<T>```/```IEnumerable``` is in type parameter's effective interfaces set.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
`allows ref strict`, there is no `GetEnumerator` pattern match, and ```IEnumerable<T>```/```IEnumerable``` is in type parameter's effective interfaces set.
`allows ref struct`, there is no `GetEnumerator` pattern match, and ```IEnumerable<T>```/```IEnumerable``` is in type parameter's effective interfaces set.

Copy link
Member

Choose a reason for hiding this comment

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

A foreach statement will recognize and use implementation of IEnumerable<T>/IEnumerable interface when collection is a type parameter that
allows ref strict, there is no GetEnumerator pattern match, and IEnumerable<T>/IEnumerable is in type parameter's effective interfaces set.

Currently, it looks like we use IEnumerable<T> even if there is a GetEnumerator pattern (available through an interface) - see sharplab.io.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

A foreach statement will recognize and use implementation of IEnumerable<T>/IEnumerable interface when collection is a type parameter that
allows ref strict, there is no GetEnumerator pattern match, and IEnumerable<T>/IEnumerable is in type parameter's effective interfaces set.

Currently, it looks like we use IEnumerable<T> even if there is a GetEnumerator pattern (available through an interface) - see sharplab.io.

I can see how this could be confusing, but there is no pattern match in this case due to an ambiguity.

proposals/ref-struct-interfaces.md Outdated Show resolved Hide resolved
```

An `await foreach` statement will recognize and use implementation of ```IAsyncEnumerable<T>``` interface when collection is a type parameter that
`allows ref strict`, there is no `GetAsyncEnumerator` pattern match, and ```IAsyncEnumerable<T>``` is in type parameter's effective interfaces set.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
`allows ref strict`, there is no `GetAsyncEnumerator` pattern match, and ```IAsyncEnumerable<T>``` is in type parameter's effective interfaces set.
`allows ref struct`, there is no `GetAsyncEnumerator` pattern match, and ```IAsyncEnumerable<T>``` is in type parameter's effective interfaces set.

Copy link
Member

Choose a reason for hiding this comment

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

An await foreach statement will recognize and use implementation of IAsyncEnumerable<T> interface when collection is a type parameter that
allows ref strict, there is no GetAsyncEnumerator pattern match, and IAsyncEnumerable<T> is in type parameter's effective interfaces set.

Currently, IAsyncEnumerable<T> is used even if there is a GetAsyncEnumerator pattern (available through an interface) - see sharplab.io.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

An await foreach statement will recognize and use implementation of IAsyncEnumerable<T> interface when collection is a type parameter that
allows ref strict, there is no GetAsyncEnumerator pattern match, and IAsyncEnumerable<T> is in type parameter's effective interfaces set.

Currently, IAsyncEnumerable<T> is used even if there is a GetAsyncEnumerator pattern (available through an interface) - see sharplab.io.

I can see how this could be confusing, but there is no pattern match in this case due to an ambiguity.

proposals/ref-struct-interfaces.md Outdated Show resolved Hide resolved
AlekseyTs added a commit to dotnet/roslyn that referenced this pull request Apr 8, 2024
@AlekseyTs AlekseyTs merged commit b349045 into main Apr 8, 2024
1 check passed
@AlekseyTs AlekseyTs deleted the AlekseyTs-patch-7 branch April 8, 2024 12:39
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.

5 participants