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

Recognize "(field as IDisposable)?.Dispose()" #744

Merged
merged 1 commit into from
May 29, 2024

Conversation

manfred-brands
Copy link
Member

Fixes #743

Also adds recognition of System.IDisposable in addition to IDisposable

@manfred-brands manfred-brands requested a review from mikkelbu May 28, 2024 14:29
Copy link
Member

@mikkelbu mikkelbu left a comment

Choose a reason for hiding this comment

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

Looks good to me. I only have a single question, but I'm happy to merge it when you are.

As usual a nice and simple addition @manfred-brands

typeIdentifierName.Identifier.Text.Equals("IDisposable", StringComparison.Ordinal))
// considering cast to I(Async)Disposable, e.g. in case of explicit interface implementation of IDisposable.Dispose()
// or in case of 'as IDisposable' or 'as IAsyncDisposable'
// or in case of 'is IDisposable' or 'is IAsyncDisposable'
Copy link
Member

Choose a reason for hiding this comment

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

Mostly a comment - as I think the code below looks good for cast and as-pattern, but I don't think is is handled here (only in lines 481-486) or am I overlooking something?

Copy link
Member Author

Choose a reason for hiding this comment

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

No you are right, I added the comment until my nunit tests proofed me wrong that it was done when checking if statement.

@manfred-brands manfred-brands merged commit 5dee0c1 into nunit:master May 29, 2024
6 checks passed
@manfred-brands manfred-brands deleted the issue743_Dispose branch May 29, 2024 05:13
@mikkelbu mikkelbu added this to the Release 4.3 milestone Jun 5, 2024
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.

NUnit1032 (missing Dispose), if dispose is wrapped in "(… as IDisposable)?.Dispose()"
2 participants