gleam-lang/gleam · error

This is an extra type specifier

Error message

This is an extra type specifier

What it means

Raised as ErrorType::ConflictingTypeOptions when a bit array segment specifies more than one type option (e.g. int, float, bytes, bits, utf8, utf16, utf32, or utf*_codepoint). A segment can have exactly one type; the second type option triggers this error at the location of the offending option.

Solutions

  1. Remove the redundant type specifier, keeping only one type per segment
  2. If you intended a sizing option, use 'size:n' or 'unit:n' instead of a second type
  3. Merge intent into a single type that matches the data (e.g. choose bytes vs utf8, not both)

Example fix

// before
let assert <<header:32:float>> = data
// after
let assert <<header:float>> = data
Defensive patterns

Strategy: validation

Validate before calling

// Count type options before writing a segment: exactly one of
// int | float | bytes | bits | utf8 | utf16 | utf32 | utf8_codepoint | utf16_codepoint | utf32_codepoint
fn count_type_options(spec: String) -> Int {
  ["int", "float", "bytes", "bits", "utf8", "utf16", "utf32"]
  |> list.filter(fn(t) { string.contains(spec, ":" <> t) })
  |> list.length
}

Prevention

When it happens

Trigger: Writing two type specifiers on one segment, such as <<x:int:float>> or <<data:bytes:utf8>>, in either a bit array expression or a pattern.

Common situations: Typos where the author meant a size or unit option but wrote a second type; copy-paste edits that left a stale type option behind; misunderstanding that ':utf8' is a type, not a modifier.

Related errors


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

Appendix: source

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

                        target,
                        option: UnsupportedOption::UtfCodepointPattern,
                    },
                    option.location(),
                );
            }

            Bytes { .. }
            | Int { .. }
            | Float { .. }
            | Bits { .. }
            | Utf8 { .. }
            | Utf16 { .. }
            | Utf32 { .. }
            | Utf8Codepoint { .. }
            | Utf16Codepoint { .. }
            | Utf32Codepoint { .. } => {
                if let Some(previous) = categories.type_ {
                    return err(
                        ErrorType::ConflictingTypeOptions {
                            existing_type: previous.label(),
                        },
                        option.location(),
                    );
                } else {
                    categories.type_ = Some(option);
                }
            }

            Signed { .. } | Unsigned { .. } => {
                if let Some(previous) = categories.signed {
                    return err(
                        ErrorType::ConflictingSignednessOptions {
                            existing_signed: previous.label(),
                        },
                        option.location(),
                    );

View on GitHub (pinned to 15b07c7830)