gleam-lang/gleam · error · ErrorType

ErrorType::SignednessUsedOnNonInt

Error message

ErrorType::SignednessUsedOnNonInt { type_: opt.label() }

What it means

In Gleam bit array segments, the `signed`/`unsigned` option is only meaningful for integer-typed segments. The compiler's `type_options` in compiler-core/src/bit_array.rs rejects a segment that declares signedness when the segment's explicit type annotation is not an integer (e.g. float, utf8, bit_array). The error reports the offending type's label via `opt.label()` at the signedness option's location.

Solutions

  1. Remove the `signed`/`unsigned` option from segments whose type is not an integer.
  2. If a signed integer was intended, annotate the segment as an integer type, e.g. `<<x:int-signed>>`.
  3. If a float or string segment was intended, keep only options valid for that type (e.g. `size`, `big`/`little`).

Example fix

// before
let a = <<3.14:float-signed>>
// after
let a = <<3.14:float>>
// or for a signed integer:
let b = <<3:int-signed>>
Defensive patterns

Strategy: validation

Validate before calling

// Gleam checks this at compile time; guard at authoring time.
// Only apply signedness to int segments:
// let ok  = <<value:int-signed>>
// let bad = <<value:float-signed>>
fn signedness_allowed(type_label: String) -> Bool {
  type_label == "Int"
}

Prevention

When it happens

Trigger: Combining `signed`/`unsigned` with a non-integer type in a bit array segment, e.g. `<<1.5:float-signed>>` or `<<x:utf8-signed>>`, in either a bit array expression or a pattern (raised via `type_options_for_value` / `type_options_for_pattern`).

Common situations: Porting Erlang/Elixir bit syntax where signedness rules differ; typos attaching `:signed` to float or string segments; early confusion about which options apply to which segment types.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of gleam-lang/gleam@15b07c7830 (2026-09-14). Data as JSON: /api/errors/62ba2612533394f0. Report an issue: GitHub.

Appendix: source

Thrown at compiler-core/src/bit_array.rs:262

            ..
        } => return err(ErrorType::InvalidEndianness, endian.location()),

        _ => {}
    }

    // signed and unsigned can only be used with int types
    match categories {
        SegmentOptionCategories {
            type_: None | Some(Int { .. }),
            ..
        } => {}

        SegmentOptionCategories {
            type_: Some(opt),
            signed: Some(sign),
            ..
        } => {
            return err(
                ErrorType::SignednessUsedOnNonInt { type_: opt.label() },
                sign.location(),
            );
        }

        _ => {}
    }

    // utf8, utf16, utf32 exclude unit and size
    match categories {
        SegmentOptionCategories {
            type_: Some(type_),
            unit: Some(unit),
            ..
        } if is_unicode(type_) => {
            return err(
                ErrorType::TypeDoesNotAllowUnit {
                    type_: type_.label(),

View on GitHub (pinned to 15b07c7830)