Skip to content
Latchkey

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

  1. Read the "got" versus "expected" line to see the exact types.
  2. Apply the right conversion ($ for stringify, float(x), int(x)).
  3. Rebuild to confirm an overload now matches.
main.nim
writeLine(stdout, $count)   # stringify the int

Add 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 = $n

How to prevent it

  • Convert explicitly between numeric and string types.
  • Read the candidate overload list to see what the compiler tried.
  • Run nim check in CI to surface type errors before codegen.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →