Skip to content
Latchkey

Go "constant overflows type" in CI

Go checks at compile time that a constant fits the type it is being assigned to. A value outside the type range (for example 300 into an int8) is rejected as "overflows".

What this error means

Compilation fails with "constant 300 overflows int8" (or uint8, int16, and so on) at an assignment or conversion.

go build
./limits.go:5:18: constant 300 overflows int8

Common causes

The constant is larger than the type holds

A sized integer type like int8 (max 127) cannot hold the literal, so the compiler refuses the assignment.

A negative literal assigned to an unsigned type

Assigning a negative constant to a uint-family type overflows because unsigned types start at zero.

How to fix it

Widen the type or correct the value

  1. Decide whether the value or the type is wrong.
  2. Use a wider integer type, or change the constant to fit the intended type.
  3. Rebuild to confirm the constant fits.
limits.go
var max int16 = 300 // int16 holds up to 32767

Use an unsigned type only for non-negative values

Reserve uint types for values that are never negative; otherwise use a signed type.

How to prevent it

  • Pick integer widths that comfortably hold the expected range.
  • Be deliberate when assigning literals to sized integer types.
  • Let CI compile the package so overflowing constants are caught.

Related guides

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