Skip to content
Latchkey

Go "cannot use X as Y value in argument" - Fix in CI

Go is statically typed and will not implicitly convert between types. Passing a value whose type does not match the parameter is a compile error.

What this error means

A build fails with cannot use x (variable of type A) as type B value in argument to f. It commonly appears after a signature change or a refactor that altered a value type.

go
./api.go:18:14: cannot use id (variable of type int64) as type string value in argument to lookup

Common causes

Signature changed

A function parameter type changed but a caller still passes the old type.

Missing explicit conversion

Go requires an explicit conversion between numeric or named types; the call omitted it.

How to fix it

Convert the value explicitly

  1. Wrap the argument in the target type conversion, or fix the caller to pass the right type.
Go
lookup(strconv.FormatInt(id, 10))

Align caller and signature

  1. Update all callers after changing a function signature, then rebuild.
Terminal
go build ./...

How to prevent it

  • Update all call sites when you change a signature.
  • Build locally before pushing to catch type mismatches.
  • Prefer explicit conversions over relying on inference.

Frequently asked questions

What causes ""cannot use X as Y value""?
A function parameter type changed but a caller still passes the old type.
How do I fix "cannot use X as Y value"?
Convert the value explicitly

Related guides

References

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