A function calls itself before anything could stop it, so it recurses until the stack overflows
What it finds
func (c Celsius) Value() float64 { return c.Value() }: the call comes before any condition or return, so every call makes another one until the goroutine's stack is exhausted and the program dies. Usually a field, an embedded value or a function of another package with the same name was meant.
A statement of the function's body itself, before the first statement that could branch or leave (if, switch, select, for, go, defer, a label, return of anything else, goto or panic), must call the function: a plain function by its name, or a method through the receiver's name, and not inside a function literal or behind && or ||. Names are resolved, so a call of a shadowing variable or of a package's function is not mistaken for one.
From the rule's source, unconditional_recursion.rs.
package p type celsius float64 func (c celsius) Value() float64 { return c.Value()tx0 reports: Value calls itself before anything can stop it} func positive(n int) bool { return n > 0 && positive(n-1) } func countdown(n int) int { if n == 0 { return 0 } return countdown(n - 1)} func loop(n int) { println(n) loop(n + 1)tx0 reports: loop calls itself before anything can stop it} type wrapper struct{ inner *wrapper } func (w *wrapper) Close() error { return w.inner.Close() } 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:
[rules]
"tx0/go:unconditional-recursion" = "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/go:unconditional-recursion] reason="..."tx0 explain tx0/go:unconditional-recursion shows the same in the terminal. Found a false positive? Report it.