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

Allow pattern-based disposal in foreach #32317

Closed
jcouv opened this issue Jan 10, 2019 · 1 comment
Closed

Allow pattern-based disposal in foreach #32317

jcouv opened this issue Jan 10, 2019 · 1 comment

Comments

@jcouv
Copy link
Member

jcouv commented Jan 10, 2019

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.

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:

  1. A pattern enumerable type did not implement IDisposable, but had a
    Dispose method. This method would now be call.
  2. 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.


Umbrella for enhanced-using feature: #28588

@jcouv jcouv added Area-Compilers Feature - enhanced using Using pattern and declaration labels Jan 10, 2019
@jcouv jcouv added this to the 16.0.P3 milestone Jan 10, 2019
@jcouv jcouv modified the milestones: 16.0.P3, 16.1.P1 Feb 13, 2019
@gafter gafter modified the milestones: 16.1.P1, 16.1.P3 Apr 9, 2019
@jcouv jcouv modified the milestones: 16.1.P3, 16.1, 16.2 Apr 18, 2019
@jcouv jcouv modified the milestones: 16.2, Compiler.Next Jun 19, 2019
@chsienki
Copy link
Contributor

This is implemented and working

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

3 participants