Credence.Semantic.UsedUnderscoreVariable (credence v0.5.0)

Copy Markdown

Fixes compiler warnings about underscored variables that are referenced after being set, by removing the leading underscore.

LLMs often generate function heads where a parameter is underscore-prefixed (signalling "unused") but then referenced in a guard or the function body:

defp helper(_target_n, index, _acc) when index > _target_n do
  Enum.reverse(_acc)
end

The underscore prefix signals "unused," but the guard and body reference the variables. This produces compiler warnings that become hard errors under --warnings-as-errors.

The fix finds the enclosing function clause and renames the variable throughout the entire clause (both the parameter declaration and all usages in the guard/body), leaving other clauses untouched.