gleam-lang/gleam · error · TypeError

This is an extra type specifier

Error message

This is an extra type specifier

What it means

Gleam compile error (BitArraySegmentError::ConflictingTypeOptions): a single bit array segment was given more than one type specifier. The compiler treats bytes, int, float, bits, utf8, utf16, utf32, utf8_codepoint, utf16_codepoint, and utf32_codepoint as type options; once categories.type_ is set by the first one, any later type option in the same segment triggers this error. The diagnostic labels the second occurrence 'This is an extra type specifier' and adds a hint naming the type already in effect (e.g. 'This segment already has the type int.').

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 3e3c5ddc08)

Solutions

  1. Keep exactly one type option per segment: delete the duplicate specifier flagged by 'This is an extra type specifier'
  2. If two typed values were intended, split into two segments separated by a comma: <<1:int, x:bytes>>
  3. Read the hint line naming the existing type and the linked tour.gleam.run bit-array guide

Example fix

// before
let x = <<1:int-bytes>>

// after (one type per segment; use a comma for multiple segments)
let x = <<1:int, rest:bytes>>
Defensive patterns

Strategy: validation

Validate before calling

# surface duplicate type options immediately after editing bit arrays
gleam check

Prevention

When it happens

Trigger: Writing a segment with two type options such as '<<1:int-bytes>>' or '<<"x":utf8-utf16>>' — typically when '-' was intended as a segment separator rather than an option separator inside one segment. The snapshot test 'let x = <<1:int-bytes>>' shows the canonical case.

Common situations: Newcomers writing bit arrays for the first time combining int/bytes or utf variants in one segment; copying binary-syntax from Erlang where meanings differ; quick edits that leave a stale option behind.

Related errors


AI-assisted analysis of gleam-lang/gleam@3e3c5ddc08 (2026-08-20). Data as JSON: /api/errors/94389fab5c18266a. Report an issue: GitHub.