Credence.FunctionMatcher
(credence v0.6.0)
Copy Markdown
Finds the closest matching defined function for an undefined function call.
When the compiler reports undefined function NAME/ARITY, this module
searches the source for defined functions in the same module with matching
arity and ranks them by name similarity. Used by UndefinedLocalFunction
and UndefinedFunction to fix misspelled or mangled function calls.
Scoring ladder
| Score | Match type |
|---|---|
| 100 | Exact name + ? suffix (palindrome → palindrome?) |
| 95 | Exact name + ! suffix (save → save!) |
| 90 | __ demangles to ? (perfect__ → perfect?) |
| 85 | __ demangles to ! (save__ → save!) |
| 80 | Candidate is prefix of name (fib ← fibonacci) |
| 75 | Name is prefix of candidate (find → find_largest) |
| 70 | One contains the other (fibonacci ∈ do_fibonacci) |
| 0–60 | Jaro distance scaled to 0–60 |
The module never "gives up" — if any function with matching arity exists, it's returned. The pipeline validates the fix by compiling.
Summary
Functions
Returns all candidate functions with matching arity, sorted by score
descending. Each candidate has :name, :arity, :visibility, and :score.
Returns the best matching function name, or :no_candidates if the
module has zero functions with the given arity.
Types
@type candidate() :: %{ name: String.t(), arity: non_neg_integer(), visibility: :def | :defp, score: non_neg_integer() }
Functions
Returns all candidate functions with matching arity, sorted by score
descending. Each candidate has :name, :arity, :visibility, and :score.
@spec suggest(String.t(), String.t(), String.t(), non_neg_integer(), keyword()) :: {:ok, String.t()} | :no_candidates
Returns the best matching function name, or :no_candidates if the
module has zero functions with the given arity.