Nim "Error: type mismatch" in CI
Nim could not match the argument or assignment to any compatible overload. It prints "type mismatch: got <X> but expected <Y>" and lists the candidate procs it tried.
What this error means
Compilation fails with "Error: type mismatch: got <...> but expected <...>" and an "expression: ..." line, plus the list of overloads that did not match.
nim
src/main.nim(5, 17) Error: type mismatch: got <int> but expected 'string'
expression: writeLine(stdout, count)Common causes
An argument has the wrong type
You passed an int where a string is required (or similar), and no overload accepts that combination.
A missing conversion between numeric or distinct types
Nim does not implicitly convert across many types, so an int and a float, or a distinct type and its base, need an explicit conversion.
How to fix it
Convert the value to the expected type
- Read the "got" versus "expected" line to see the exact types.
- Apply the right conversion (
$for stringify,float(x),int(x)). - Rebuild to confirm an overload now matches.
main.nim
writeLine(stdout, $count) # stringify the intAdd an overload that accepts the type
If the call is intentional, define a proc whose signature matches what you pass.
main.nim
proc render(n: int): string = $nHow to prevent it
- Convert explicitly between numeric and string types.
- Read the candidate overload list to see what the compiler tried.
- Run
nim checkin CI to surface type errors before codegen.
Related guides
Nim "Error: undeclared identifier" in CIFix Nim "Error: undeclared identifier: X" in CI - a name is used before it is defined or imported, often a mi…
Nim "Error: cannot open file" in CIFix Nim "Error: cannot open file: X" in CI - the compiler could not find a module on its search path because…
Nim "execution of an external program failed: gcc" in CIFix Nim "Error: execution of an external program failed: gcc" in CI - Nim generated C but the backend C compi…