Skip to content

IDE0019 Syntactic Sugar Quick Fix creates functionally different code that can introduce a memory leak #45596

@BrainSlugs83

Description

@BrainSlugs83

Version Used: Visual Studio Enterprise 2019 16.6.1 / .NET Core 3.1

Steps to Reproduce:
Consider the following Code:

using var myObj = GetData() as MyObject;
if (myObj != null)
// ...

This triggers IDE0019 "Use pattern matching" information message in the Error List.

I click "Quick Fix", and it gives me this:

if (GetData() is MyObject myObj)
// ...

This quick fix is removing my using block and producing code that is not functionally equivalent; in this case, it is introducing a new memory leak vector.

(Yes, it's possible there was one there already if another object type was returned, but the quick fix code makes it worse, and is not even functionally equivalent to what I had before.)

Expected Behavior:

Quick fixes for syntactic sugar features should NOT change the functionality of the code. -- In this case it should not be removing the using block.

Additionally, if a quick fix is not available, I would prefer to not see the informational message in my error list window either (since the syntactic sugar equivalent of my code would actually be longer).

Actual Behavior:
The IDE is effectively warning me that my application doesn't have enough memory leaks, and is offering to insert a new one for me in the guise of a syntactic sugar warning and suggested quick fix.

Metadata

Metadata

Assignees

Labels

Area-IDEBughelp wantedThe issue is "up for grabs" - add a comment if you are interested in working on it

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions