gleam-lang/gleam · error · ErrorType

ErrorType::ConflictingEndiannessOptions

Error message

ErrorType::ConflictingEndiannessOptions { existing_endianness: previous.label() }

What it means

A validation error produced by `type_options` (called from `type_options_for_value` and `type_options_for_pattern`) when checking bit array segment options. Each segment may declare endianness (Big, Little, or Native) at most once; this error fires when a second, conflicting endianness option appears after one was already given (e.g. `<<x:little:big>>`). On JavaScript the Native option is rejected separately via OptionNotSupportedForTarget; everywhere else duplicate endianness options are reported as ConflictingEndiannessOptions, naming the previously seen option's label.

Solutions

  1. Remove all but one endianness option from the segment
  2. Standardize on the byte order the format specifies (commonly big-endian)
  3. Search the segment option list for stray big/little/native duplicates

Example fix

// before
<<payload:bits-size(16)-little-big>>
// after
<<payload:bits-size(16)-little>>
Defensive patterns

Strategy: validation

Validate before calling

// At most one of big | little | native per segment
fn endianness_option_count(spec: String) -> Int {
  ["-big", "-little", "-native"]
  |> list.filter(fn(e) { string.contains(spec, e) })
  |> list.length
}

Prevention

When it happens

Trigger: A segment with two endianness options such as <<x:int-big-little>> or <<x:float-native-big>> in an expression or pattern; type_options detects categories.endian already populated.

Common situations: Incremental edits switching endianness without removing the old option; copy-pasted option chains; misunderstanding that options replace rather than accumulate.

Related errors


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

Appendix: source

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

                    );
                } else {
                    categories.signed = Some(option);
                }
            }

            Native { .. } if target == Target::JavaScript => {
                return err(
                    ErrorType::OptionNotSupportedForTarget {
                        target,
                        option: UnsupportedOption::NativeEndianness,
                    },
                    option.location(),
                );
            }

            Big { .. } | Little { .. } | Native { .. } => {
                if let Some(previous) = categories.endian {
                    return err(
                        ErrorType::ConflictingEndiannessOptions {
                            existing_endianness: previous.label(),
                        },
                        option.location(),
                    );
                } else {
                    categories.endian = Some(option);
                }
            }

            Size { .. } => {
                if categories.size.is_some() {
                    return err(ErrorType::ConflictingSizeOptions, option.location());
                } else {
                    categories.size = Some(option);
                }
            }

View on GitHub (pinned to 15b07c7830)