You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The compiler will bind to the pattern-based APIs if they exist, preferring those over using the interface (the pattern may be satisfied with instance methods or extension methods).
The text was updated successfully, but these errors were encountered:
@jcouv I were really surprised that just DisposeAsync is not preferring pattern based methods...
I found no clear statement about it in the spec - but for consistency reasons I agree that this is maybe a bug...
Your sample is a bit wrong - because the non interface GetAsyncEnumerator method is not invocable without a parameter. In this case the compiler must call the interface based method (the enumerator is of type IAsyncEnumerator<int>).
But if you change that - the compiler still uses the explicit interface implementation of DisposeAsync. This is not really a big problem because it is executed with a constrained call - no Boxing:
Re: "I found no clear statement about it in the spec"
I've added a note to OP with the statement from async-streams spec that clarifies expectations:
The compiler will bind to the pattern-based APIs if they exist, preferring those over using the interface (the pattern may be satisfied with instance methods or extension methods).
In the situation where a type can be implicitly converted to IDisposable and also fits the disposable pattern, then IDisposable will be preferred. While this takes the opposite approach of foreach (pattern preferred over interface) it is necessary for backwards compatibility.
Tagging @chsienki in case the precedence order as implemented was intended (TL;DR: foreach generally picks pattern-based first, then interface; async-streams spec agree; but implementation does reverse).
The following prints
IAsyncDisposable.DisposeAsync()
:See sharplab.io.
From async-streams spec:
The text was updated successfully, but these errors were encountered: