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.
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
- Read the "Overloads are" list to see the accepted parameter types.
- Convert the argument (
.to_s,.to_i) so it matches an overload. - Rebuild to confirm a match.
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.
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.