{"record":{"id":"fe9679771dd1f2a6","repo":"gleam-lang/gleam","slug":"aliased-non-constant-value-value","errorCode":null,"errorMessage":"aliased non constant value: {value:#?}","messagePattern":"aliased non constant value: (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"compiler-core/src/exhaustiveness.rs","lineNumber":510,"sourceCode":"            segment_name,\n            BoundValue::BitArraySlice {\n                bit_array,\n                read_action: value,\n            },\n        ));\n    }\n\n    fn assign_segment_constant_value(&mut self, name: EcoString, value: &BitArrayMatchedValue) {\n        let value = match value {\n            BitArrayMatchedValue::LiteralFloat(value) => BoundValue::LiteralFloat(value.clone()),\n            BitArrayMatchedValue::LiteralInt { value, .. } => BoundValue::LiteralInt(value.clone()),\n            BitArrayMatchedValue::LiteralString { value, .. } => {\n                BoundValue::LiteralString(value.clone())\n            }\n            BitArrayMatchedValue::Variable(_)\n            | BitArrayMatchedValue::Discard(_)\n            | BitArrayMatchedValue::Assign { .. } => {\n                panic!(\"aliased non constant value: {value:#?}\")\n            }\n        };\n\n        self.bindings.push((name, value));\n    }\n}\n\n/// A user defined pattern such as `Some((x, 10))`.\n/// This is a bit simpler than the full fledged `TypedPattern` used for code analysis\n/// and only focuses on the relevant bits needed to perform exhaustiveness checking\n/// and code generation.\n///\n/// Using this simplified version of a pattern for the case compiler makes it a\n/// whole lot simpler and more efficient (patterns will have to be cloned, so\n/// we use an arena to allocate those and only store ids to make this operation\n/// extra cheap).\n///\n#[derive(Clone, Eq, PartialEq, Debug)]","sourceCodeStart":492,"sourceCodeEnd":528,"githubUrl":"https://github.com/gleam-lang/gleam/blob/49f8762da595eb3c8f576656a4200a142ca188c9/compiler-core/src/exhaustiveness.rs#L492-L528","documentation":"This is an internal compiler panic raised in `assign_segment_constant_value` (compiler-core/src/exhaustiveness.rs:486). While computing bindings for a bit array segment pattern, only literal string segments carry a constant value that can be bound to an alias. If the matched value is a `Variable`, `Discard`, or `Assign` variant, no constant exists to alias, and the compiler asserts this invariant with a panic. Hitting it means the pattern-computation phases produced a shape that constant-binding was not designed to accept.","triggerScenarios":"Compiling a `<<..>>` bit array pattern where a segment binds a name (`alias = pattern`) but the resolved `BitArrayMatchedValue` is `Variable`, `Discard`, or `Assign` instead of a `LiteralString`; this only occurs if upstream match-value computation misclassifies the segment, e.g. after a compiler regression or when using nightly/patched builds with custom pattern handling.","commonSituations":"Gleam compiler contributors testing changes to bit array pattern matching; users building a modified fork or hitting a compiler bug on exotic bit array patterns like `<<x:size(n)>>` with aliases in case expressions; generally not reachable from valid user code on a stable release.","solutions":["Reduce the failing bit array pattern to a minimal snippet and file a bug at the gleam compiler repository with the panic debug dump (`{value:#?}`) and the source pattern.","Check your compiler version; upgrade to the latest release where the pattern-computation bug may already be fixed.","Temporarily rewrite the pattern to avoid aliasing the non-literal segment (e.g. match the segment separately) to unblock compilation.","If building a patched compiler, audit the code that constructs `BitArrayMatchedValue` for segment binding so only `LiteralString` values reach `assign_segment_constant_value`."],"exampleFix":"// before (source pattern that may trigger via compiler bug)\ncase bits { <<\"lit\":utf8>> <> rest -> ... }\n// after: split binding out if the compiler panics\nlet <<\"lit\":utf8>> = prefix\nlet rest = remainder","handlingStrategy":"type-guard","validationCode":"// only alias constant segment values\nif !matches!(value, BitArrayMatchedValue::LiteralString { .. }) {\n    return Err(...); // or handle Variable/Discard/Assign explicitly\n}","typeGuard":"fn is_constant_value(v: &BitArrayMatchedValue) -> bool {\n    matches!(v, BitArrayMatchedValue::LiteralString { .. })\n}","tryCatchPattern":null,"preventionTips":["Handle every BitArrayMatchedValue variant explicitly instead of panicking","Add unit tests for aliased bit array segments with non-literal values","Return a compiler Error rather than panicking in library code"],"tags":["panic","internal-invariant","bit-array","pattern-matching","compiler-bug"],"backgroundTag":"internal-invariant-violation","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"}