Skip to content
Latchkey

Crystal "Error: no overload matches" in CI

Crystal could not find a method definition whose parameters accept the argument types you passed. It lists the overloads it knows so you can see what types are accepted.

What this error means

Compilation fails with "Error: no overload matches 'X' with types Y" followed by an "Overloads are: ..." list of the accepted signatures.

crystal
Error: no overload matches 'File.write' with types String, Int32

Overloads are:
 - File.write(filename : Path | String, content : String | Bytes | IO, ...)

Common causes

An argument has the wrong type

You passed a type none of the overloads accept (for example an Int32 where String | Bytes | IO is required).

A nilable argument widens the type

A T? argument does not match an overload that requires T, because the union including Nil is not accepted.

How to fix it

Convert the argument to an accepted type

  1. Read the "Overloads are" list to see the accepted parameter types.
  2. Convert the argument (.to_s, .to_i) so it matches an overload.
  3. Rebuild to confirm a match.
app.cr
File.write(path, count.to_s)

Remove Nil from a nilable argument

Narrow a T? value to T before the call so it matches an overload.

app.cr
File.write(path, content.not_nil!)

How to prevent it

  • Match argument types to the documented overloads.
  • Convert numerics and other types explicitly before calls.
  • Narrow nilable values before passing them.

Frequently asked questions

What causes "Crystal "no overload matches""?
You passed a type none of the overloads accept (for example an Int32 where String | Bytes | IO is required).
How do I fix Crystal "no overload matches"?
Convert the argument to an accepted type

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card