{"record":{"id":"b895988bd515a1ac","repo":"gleam-lang/gleam","slug":"errortype-invalidendianness","errorCode":null,"errorMessage":"ErrorType::InvalidEndianness","messagePattern":"ErrorType::InvalidEndianness","errorType":"validation","errorClass":"ErrorType","httpStatus":null,"severity":"error","filePath":"compiler-core/src/bit_array.rs","lineNumber":245,"sourceCode":"    match categories {\n        SegmentOptionCategories {\n            type_:\n                None\n                | Some(\n                    Int { .. }\n                    | Utf16 { .. }\n                    | Utf32 { .. }\n                    | Utf16Codepoint { .. }\n                    | Utf32Codepoint { .. }\n                    | Float { .. },\n                ),\n            ..\n        } => {}\n\n        SegmentOptionCategories {\n            endian: Some(endian),\n            ..\n        } => return err(ErrorType::InvalidEndianness, endian.location()),\n\n        _ => {}\n    }\n\n    // signed and unsigned can only be used with int types\n    match categories {\n        SegmentOptionCategories {\n            type_: None | Some(Int { .. }),\n            ..\n        } => {}\n\n        SegmentOptionCategories {\n            type_: Some(opt),\n            signed: Some(sign),\n            ..\n        } => {\n            return err(\n                ErrorType::SignednessUsedOnNonInt { type_: opt.label() },","sourceCodeStart":227,"sourceCodeEnd":263,"githubUrl":"https://github.com/gleam-lang/gleam/blob/15b07c783065c92bb016b1b74ed0995a5259850f/compiler-core/src/bit_array.rs#L227-L263","documentation":"ErrorType::InvalidEndianness: endianness options (big/little/native) are only valid on segments whose type is int, float, utf16, utf16_codepoint, utf32, or utf32_codepoint. If a segment carries an endian option with an incompatible type (e.g. bytes, bits, utf8), the compiler rejects it at the endian option's location.","triggerScenarios":"Writing <<data:bytes-big>> or <<str:utf8-little>>; the final match in type_options finds categories.endian set while the segment's type is not one of the byte-order-compatible types.","commonSituations":"Applying endianness habitually to every segment; believing strings/bytes have byte-order semantics; copy-pasting an int segment's option list onto a bytes segment.","solutions":["Remove the endianness option from bytes/bits/utf8 segments","Change the segment's type to one that supports endianness (int, float, utf16, utf32, or their codepoints) if byte order matters","Apply endianness per numeric field rather than to whole byte blobs"],"exampleFix":"// before\n<<blob:bytes-big>>\n// after\n<<blob:bytes>>","handlingStrategy":"validation","validationCode":"// Endianness only applies to: int, float, utf16, utf32, utf16_codepoint, utf32_codepoint\nfn endian_valid(type_str: String) -> Bool {\n  [\"int\", \"float\", \"utf16\", \"utf32\", \"utf16_codepoint\", \"utf32_codepoint\"]\n  |> list.contains(type_str)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Only attach big/little/native to numeric and utf16/utf32 segments","bytes/bits/utf8 segments never take endianness — don't copy option chains between segment types","If byte order matters for a blob, split it into sized int/float segments"],"tags":["gleam","bit-array","endianness","type-mismatch"],"backgroundTag":"type-mismatch","analyzedSha":"15b07c783065c92bb016b1b74ed0995a5259850f","analyzedAt":"2026-09-14T11:14:59.388Z","contentChangedAt":"2026-09-14T11:14:59.388Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}