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

limit disposable pattern #6785

Merged
merged 1 commit into from
Dec 13, 2022

Conversation

BillWagner
Copy link
Member

@BillWagner BillWagner commented Dec 8, 2022

The proposal spec'ed this out in general terms for any type, and included a provision to allow extension Dispose methods.

The implementation only allows ref struct types to use the pattern-based Dispose. Furthermore, the Dispose method can't be an extension method.

Fixes dotnet/docs#31815

I made edits to make the proposal match the implementation. As an alternative, I could make edits to indicate which portions of the proposal were implemented and which may be delivered in the future. Let me know which you'd prefer.

The proposal spec'ed this out in general terms for any type, and included a provision to allow extension `Dispose` methods.

The implementation only allows `ref` struct types to use the pattern-based Dispose. Furthermore, the `Dispose` method can't be an extension method.

Fixes dotnet/docs#31815

I made edits to make the proposal match the implementation. As an alternative, I could make edits to indicate which portions of the proposal were implemented and which may be delivered in the future.
@BillWagner BillWagner requested a review from a team as a code owner December 8, 2022 15:59
statements.
- Extension methods will allow developers to augment types in other assemblies to participate
Copy link
Member

Choose a reason for hiding this comment

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

I confirmed from the code (TryFindDisposePatternMethod) that extension methods don't count. Tagging @chsienki to confirm this was intentional and to fix the speclet.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, extension methods we're explicitly disallowed, even for ref structs. The decision being that it would have been legal to have an extension method called 'Dispose' that previously wouldn't have been called if you used the type in a foreach. With the extension method lookup, it would now get called, which was considered too big a breaking change.

LDM notes are here: https://github.com/dotnet/csharplang/blob/3c8559f186d4c5df5d1299b0eaa4e139ae130ab6/meetings/2018/LDM-2018-12-12.md#when-we-start-recognizing-pattern-dispose-do-we-call-it-in-foreach

@BillWagner BillWagner merged commit a423537 into dotnet:main Dec 13, 2022
@BillWagner BillWagner deleted the pattern-based-using-ref-struct branch December 13, 2022 18:12
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.

Docs about "pattern-based usings" is incorrect
3 participants