A parameter is assigned before its value is read, so the argument is ignored

tx0/go:overwritten-parameterrecommendedwarningbug

What it finds

``go func scale(v, factor float64) float64 { factor = 2 return v * factor } `` The parameter is assigned before anything reads it, so the argument of every caller is ignored. Either the assignment is left over from testing, or another variable was meant.

The rule follows each function through the shared IR and asks the dataflow analysis whether the value a parameter arrives with is needed on any path. Reported are parameters whose value is never needed although the function assigns the parameter later; a parameter that is merely unused is left alone. Functions with constructs the lowering does not understand are skipped.

From the rule's source, overwritten_parameter.rs.

Example from the rule's tests
package p func scale(v, factor float64) float64 {tx0 reports: the parameter factor is assigned before its value is read	factor = 2	return v * factor} func grow(v float64) float64 {	v = v * 2	return v} func unused(v, w float64) float64 {	return v} func shadow(v float64) float64 {	if true {		v := 3.0		return v	}	return 0}
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 from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/go:overwritten-parameter" = "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/go:overwritten-parameter] reason="..."

tx0 explain tx0/go:overwritten-parameter shows the same in the terminal. Found a false positive? Report it.