{"record":{"id":"0295479689b88f3d","repo":"gleam-lang/gleam","slug":"variable-with-no-constructor","errorCode":null,"errorMessage":"variable with no constructor","messagePattern":"variable with no constructor","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"compiler-core/src/erlang/pattern.rs","lineNumber":316,"sourceCode":"        size: &'a TypedBitArraySize,\n    ) {\n        match size {\n            BitArraySize::Int {\n                int_value,\n                location,\n                ..\n            } => builder.int_expression(*location, int_value.clone()),\n            BitArraySize::Block { inner, .. } => self.bit_array_size(builder, inner),\n\n            BitArraySize::Variable {\n                constructor, name, ..\n            } => match self.variables_to_add_later.get(name) {\n                Some(AliasedLiteral::Int { value, location }) => {\n                    builder.int_expression(*location, value.clone())\n                }\n                Some(_) => panic!(\"segment size that is not int made it through type checking\"),\n                None => {\n                    let constructor = constructor.as_ref().expect(\"variable with no constructor\");\n                    match &constructor.variant {\n                        ValueConstructorVariant::ModuleConstant { literal, .. } => {\n                            self.generator.inlined_constant(builder, literal);\n                        }\n                        ValueConstructorVariant::LocalVariable { location, .. } => {\n                            builder.variable(*location, &self.generator.local_var_name(location));\n                        }\n                        ValueConstructorVariant::ModuleFn { .. }\n                        | ValueConstructorVariant::Record { .. } => panic!(\"invalid segment\"),\n                    }\n                }\n            },\n\n            BitArraySize::BinaryOperator {\n                operator,\n                left,\n                right,\n                location,","sourceCodeStart":298,"sourceCodeEnd":334,"githubUrl":"https://github.com/gleam-lang/gleam/blob/15b07c783065c92bb016b1b74ed0995a5259850f/compiler-core/src/erlang/pattern.rs#L298-L334","documentation":"This is an internal compiler invariant panic in Erlang code generation for bit array patterns. After type checking, every variable used as a bit array segment size must either be a known aliased literal or have a resolved `ValueConstructor` (local variable, module constant, etc.). When a variable reaches `Pattern` codegen with `constructor: None`, the compiler has no way to emit code for it and panics with `expect(\"variable with no constructor\")`.","triggerScenarios":"Compiling a Gleam bit array pattern whose segment size references a variable that lacks a constructor entry — typically the result of a type-checker/codegen mismatch, e.g. a size expression naming a variable introduced by an alias or import that was not registered during analysis, or a compiler bug where an aliased-literal entry has a non-int variant (`Some(_) => panic!(\"segment size that is not int made it through type checking\")` is the sibling check).","commonSituations":"Users hitting this have usually written an unusual bit array pattern (e.g. `<<x:size(n)>>` where `n` comes from a constant or alias) on a Gleam version with a codegen bug. It surfaces as a compiler panic (ICE) rather than a user-facing diagnostic.","solutions":["Reduce the failing bit array pattern to a minimal example and file a bug against the Gleam compiler (this is an internal invariant violation)","Upgrade to the latest Gleam version — such codegen invariants are frequently fixed in patch releases","Work around by binding the size to a plain local variable before the pattern, or inlining a literal size instead of a constant/alias reference"],"exampleFix":"// before (Gleam, suspected buggy shape)\nlet n = 16\nassert <<x:size(n)>> = data\n// after (workaround: literal or pre-bound plain variable)\nassert <<x:size(16)>> = data","handlingStrategy":"fallback","validationCode":"// Gleam-side pre-check: ensure bit-array size references a plain literal or simple local\n// e.g. prefer `<<x:size(16)>>` over `<<x:size(n)>>` where n comes from a constant/alias","typeGuard":null,"tryCatchPattern":"// compiler panics cannot be caught; wrap the compiler invocation in the shell:\ngleam build || echo \"compiler panicked (ICE) — reduce snippet and file a bug\"","preventionTips":["Keep bit-array segment sizes as literals or plainly-bound locals","Pin and regularly update the Gleam compiler version in CI","Reduce failing patterns to a snippet and report; avoid aliases/constants in size expressions until fixed"],"tags":["rust","compiler","codegen","bit-array","invariant"],"backgroundTag":"internal-invariant-violation","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"}