You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
However, in some cases, the error results in a false positive, where the compiler would throw if the assignment was removed. This happens if the local is assigned within a try/finally block (say, by a method call returning an out), and then used in the finally block. If the method call throws an exception, the local could be left uninitialized.
ahsonkhan
changed the title
LGTM.com - false positive - cs/useless-assignment-to-local when assigned within a try/finally block
LGTM.com - false positive - cs/useless-assignment-to-local when assigned as an out within a try/finally block
Feb 4, 2020
Description of the false positive
In general, the
cs/useless-assignment-to-local
rule makes sense: https://lgtm.com/rules/1506093386171/However, in some cases, the error results in a false positive, where the compiler would throw if the assignment was removed. This happens if the local is assigned within a try/finally block (say, by a method call returning an
out
), and then used in the finally block. If the method call throws an exception, the local could be left uninitialized.Here's a simplified example:
URL to the alert on the project page on LGTM.com
https://lgtm.com/projects/g/dotnet/corefx/latest/files/src/System.Text.Json/src/System/Text/Json/Document/JsonDocument.cs?sort=name&dir=ASC&mode=heatmap#V898
The text was updated successfully, but these errors were encountered: