A local variable has the same name as a field of its type, which it hides
What it finds
Inside the scope of a local variable named like a field, the bare name means the local; the field is reachable only through this.. Code that meant the field then silently reads or writes the local. Parameters are left alone, since constructors and setters name them after fields on purpose.
From the rule's source, local_shadows_field.rs.
class Counter{ private int count; void Add() { int count = 1;tx0 reports: the local count hides the field of the same name this.count += count; }} Turn it on, off or suppress it
The rule runs from the strict tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/csharp:local-shadows-field" = "warning"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
// tx0: ignore[tx0/csharp:local-shadows-field] reason="..."tx0 explain tx0/csharp:local-shadows-field shows the same in the terminal. Found a false positive? Report it.