-
Notifications
You must be signed in to change notification settings - Fork 4.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
Need an analyzer to warn about ignored Dispose
method
#32400
Comments
@jcouv Why doesn't the compiler report a clear warning for this case (extension |
@sharwell We don't want to break existing code. You could have an existing To illustrate the purpose of this analyzer, consider someone who changes their ref struct enumerable/enumerator (with a |
@jcouv My understanding is existing code will not be broken. Code will fall into three cases:
This issue targets situation 3, reporting an error that a pattern-based dispose was not used instead of the current error saying the type must be disposable. |
A |
@sharwell Did my reponse make sense? I still think this should be addressed by an analyzer warning rather than a compiler warning. |
In C# 8.0, we're adding support for pattern-based disposal. Due to compatibility concerns, the feature is restricted to ref structs for
foreach
andusing
. But it not restricted forawait foreach
andawait using
.This unfortunate situation could cause user confusion. It would be useful for an analyzer to warn on
foreach
orusing
where the user might hope an instanceDispose()
method to be called but it is in fact not called.Umbrella for enhanced-using feature: #28588
The text was updated successfully, but these errors were encountered: