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
It seems that foreach only every binds disposal via the interface, and never via pattern-based approach.
I expect that foreach would bind pattern-based Dispose() methods on ref struct enumerators, at least.
Note: in that scenario, the compiler should not produce enumerator as IDisposable logic.
Note: there is a similar issue with pattern-based disposal in await foreach, except that we likely need to lift the ref struct restriction there. (see #32316)
Update (1/16): from LDM today, we've decided that extension methods will not contribute to pattern-based disposal, even if we decide they contribute for binding pattern-based GetEnumerator() in a foreach.
When we start recognizing pattern Dispose, do we call it in foreach?
Certainly, it seems very important for the feature. Since a ref struct
cannot implement interfaces, pattern Dispose is the only way to implement
disposal.
There are a number of possible breaking changes:
A pattern enumerable type did not implement IDisposable, but had a
Dispose method. This method would now be call.
If there are two Dispose extension methods, that will now produce
an ambiguity and thus a compilation error.
Conclusion
Let's narrow the pattern-based Dispose change down to ref structs only.
This means every other type will be required to implement IDisposable.
It seems that
foreach
only every binds disposal via the interface, and never via pattern-based approach.I expect that
foreach
would bind pattern-basedDispose()
methods on ref struct enumerators, at least.Note: in that scenario, the compiler should not produce
enumerator as IDisposable
logic.Note: there is a similar issue with pattern-based disposal in
await foreach
, except that we likely need to lift the ref struct restriction there. (see #32316)Update (1/16): from LDM today, we've decided that extension methods will not contribute to pattern-based disposal, even if we decide they contribute for binding pattern-based
GetEnumerator()
in aforeach
.Tagging @agocke
Per notes (emphasis mine):
When we start recognizing pattern Dispose, do we call it in foreach?
Certainly, it seems very important for the feature. Since a ref struct
cannot implement interfaces, pattern Dispose is the only way to implement
disposal.
There are a number of possible breaking changes:
Dispose method. This method would now be call.
an ambiguity and thus a compilation error.
Conclusion
Let's narrow the pattern-based Dispose change down to ref structs only.
This means every other type will be required to implement IDisposable.
Umbrella for enhanced-using feature: #28588
The text was updated successfully, but these errors were encountered: