A method calls itself with the same arguments on every path, which recurses forever

tx0/csharp:recursive-methoddefaulterrorreliability/control-flowdepth fastbug

What it finds

A method whose whole body is return Find(id);, calling itself with its own parameters unchanged, can only recurse until the stack overflows. It usually was meant to call an overload or the same method on another object. Overloads cannot be told apart from the same method without types, so only calls with exactly the method's parameters, in order, and no receiver other than this are reported.

From the rule's source, recursive_method.rs.

Example from the rule's tests
class Repository{    public string Find(int id)    {        return Find(id);tx0 reports: Find calls itself with the same arguments and recurses forever    }     public void Save(string item) => this.Save(item);tx0 reports: Save calls itself with the same arguments and recurses forever     public int Depth(int n) => n == 0 ? 0 : Depth(n - 1);}
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

Turn it on, off or suppress it

The rule runs in every tier. To turn it off for a project, set its level in tx0.toml:

tx0.toml
[rules]
"tx0/csharp:recursive-method" = "off"

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:recursive-method] reason="..."

tx0 explain tx0/csharp:recursive-method shows the same in the terminal. Found a false positive? Report it.