CA1854 Fix breaks existing code if the identifier 'value' is already used. #6287
Labels
Area-Microsoft.CodeAnalysis.NetAnalyzers
Bug
The product is not behaving according to its current intended design
Resolution-Duplicate
Analyzer
Diagnostic ID: CA1854: Prefer the 'IDictionary.TryGetValue(TKey, out TValue)' method
Analyzer source
SDK: Built-in CA analyzers in .NET 7 SDK
NuGet Package: Microsoft.CodeAnalysis.NetAnalyzers
Version: 7.0.0-preview1.22518.1 (Latest preview, but also shipped with .NET 7)
Describe the bug
If a variable named 'value' exists within the current scope, the fix of this analyzer breaks existing code.
This is not an issue for every-day-development (everyone should be smart enough to figure out an appropriate different name himself) but it is a bit of a pity for huge (legacy) code bases that should be updated ("Fix all in project/solution").
Steps To Reproduce
Note: I agree that this is bad naming in general, though 👎
Expected behavior
Actual behavior
This won't compile-
Idea to fix
How about appending a number to the generated 'value' identifier, if 'value' is already used within the current scope?
The text was updated successfully, but these errors were encountered: