{"record":{"id":"d43487a2f9644ffc","repo":"gleam-lang/gleam","slug":"invalid-segment-type-in-exhaustiveness-x","errorCode":null,"errorMessage":"invalid segment type in exhaustiveness {x:?}","messagePattern":"invalid segment type in exhaustiveness (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"compiler-core/src/exhaustiveness.rs","lineNumber":3899,"sourceCode":"                | ReadSize::VariableBits { .. }\n                | ReadSize::BinaryOperator { .. } => {\n                    let size = previous_end.clone().add_size(&segment_size);\n                    let operator = if is_last_segment {\n                        SizeOperator::Equal\n                    } else {\n                        SizeOperator::GreaterEqual\n                    };\n                    tests.push_back(BitArrayTest::Size(SizeTest { operator, size }));\n                }\n            }\n\n            let type_ = match &segment.type_ {\n                type_ if type_.is_int() => ReadType::Int,\n                type_ if type_.is_float() => ReadType::Float,\n                type_ if type_.is_string() => ReadType::String,\n                type_ if type_.is_bit_array() => ReadType::BitArray,\n                type_ if type_.is_utf_codepoint() => ReadType::UtfCodepoint,\n                x => panic!(\"invalid segment type in exhaustiveness {x:?}\"),\n            };\n\n            let read_action = ReadAction {\n                size: segment_size.clone(),\n                from: previous_end.clone(),\n                type_,\n                endianness: segment.endianness(),\n                signed: segment.signed(),\n            };\n\n            // Each segment is also turned into a match test, checking the\n            // selected bits match with the pattern's value.\n            let value = segment_matched_value(segment, None, &read_action);\n\n            // Then if the matched value is a variable that is in scope for the\n            // rest of the pattern we keep track of it, so it can be used in the\n            // following read actions as a valid size.\n            match &value {","sourceCodeStart":3881,"sourceCodeEnd":3917,"githubUrl":"https://github.com/gleam-lang/gleam/blob/49f8762da595eb3c8f576656a4200a142ca188c9/compiler-core/src/exhaustiveness.rs#L3881-L3917","documentation":"Panic in the exhaustiveness/code-generation pass (compiler-core/src/exhaustiveness.rs:3795) when a bit array segment's type is none of the supported read types: Int, Float, String (utf8), BitArray, or UtfCodepoint. The compiler maps each segment type to a low-level `ReadType`; any other type reaching this code is a compiler-internal invariant violation, so it panics with the offending type in the message.","triggerScenarios":"A bit array segment pattern whose `type_` is not int/float/string/bit-array/utf-codepoint (e.g. a bool, list, or tuple segment) surviving earlier validation and reaching exhaustiveness code generation — typically via a compiler bug or unvalidated AST from a plugin/patch, not from normal valid Gleam source.","commonSituations":"Compiler contributors modifying type checking of bit array segments; users on patched/forked compilers compiling programs with unusual segment types; testing `<<x:bool>>`-style segments that validation should have rejected earlier.","solutions":["Upgrade to the latest gleam compiler release; earlier validation should reject unsupported segment types before this pass.","Fix the source program so the bit array segment uses a supported type (`int`, `float`, `utf8` string, `bits`/bit array, or `utf_codepoint`).","If you are a compiler developer, add the missing mapping in the `match &segment.type_` or ensure the type checker rejects the segment before exhaustiveness.","File a bug with the `{x:?}` debug output and the offending pattern if it occurs on valid-looking code."],"exampleFix":"// before: unsupported segment type\nlet <<flag:bool>> = data\n// after: use a supported segment type\nlet <<flag:int>> = data","handlingStrategy":"validation","validationCode":"let supported = t.is_int() || t.is_float() || t.is_string() || t.is_bit_array() || t.is_utf_codepoint();\nif !supported { return Err(Error::UnsupportedSegmentType); }","typeGuard":"fn is_supported_read_type(t: &Type) -> bool {\n    t.is_int() || t.is_float() || t.is_string() || t.is_bit_array() || t.is_utf_codepoint()\n}","tryCatchPattern":null,"preventionTips":["Reject unsupported segment types during type checking, before exhaustiveness","Cover all segment types in tests","Keep the ReadType mapping exhaustive with a compile-time match"],"tags":["panic","internal-invariant","bit-array","type-mismatch","compiler"],"backgroundTag":"unsupported-operation","analyzedSha":"49f8762da595eb3c8f576656a4200a142ca188c9","analyzedAt":"2026-09-14T11:14:59.388Z","contentChangedAt":"2026-09-14T11:14:59.388Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}