-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Champion: extensions in pattern-based statements (16.3, Core 3) #2135
Comments
Does this cover Dispose extension methods where the parameter uses |
As mentioned in #2133 (comment) could we consider supporting pattern-based disposal for |
From discussion in LDM today, extensions should not participate in pattern-based disposal. The main scenario that seemed interesting is to allow |
That's a shame. Allowing extensions to participate in pattern-based disposal (as well as permitting pattern-based disposal for |
Given that there's hopes to add a more formal definition of an extension type in a future major release (C# 9 ?), would it be sensible to avoid making too many changes now which would be rendered unnecessary in the future? |
@YairHalberstadt There is a championed issue for extension everything (#192) and another one for adding an interface after-the-fact (#110). |
As well as the roles shapes and extensions one created by Mads |
It was noticed that using pattern-based public void M(ref Foo foo) {
using (foo) {
}
} results in:
|
From my reading of hte spec (which is admittedly light here), i think this is due to https://github.com/dotnet/csharplang/blob/master/spec/statements.md#the-using-statement:
So even if you just have an identifier name in |
Now: there's an open question of if we want that behavior. And, if we do, if we want some way for someone to say "can you please not copy these structs? i'm using 'ref' for a reason, and htis is basically defeating the purpose there". |
Makes sense. Seems it's to guard against reassignment of the variable as the warning when you do reassign does explicitly state that
Given that the compiler is detecting this reassignment it would be nice if it only had to make the defensive copy in the case that the variable is reassigned. |
Scenarios:
using
statements and declarations, andforeach
should findDispose()
extension methods (on ref structs)await using
statements and declarations, andawait foreach
should findDisposeAsync()
extension methods (on any type)foreach
statements should findGetEnumerator()
extension methods on ref structsawait foreach
statements should findGetAsyncEnumerator()
extension methods (on any type)We should review other pattern-based statements
Being pattern-based means:
FYI @gafter
Relates to
using
statement to structurally matchIDisposable
on ref structs (16.3, Core 3) #1623 (enhanced-using)The text was updated successfully, but these errors were encountered: