{"record":{"id":"772864842e9b10bb","repo":"gleam-lang/gleam","slug":"segment-size-that-is-not-int-made-it-through-type-checking","errorCode":null,"errorMessage":"segment size that is not int made it through type checking","messagePattern":"segment size that is not int made it through type checking","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"compiler-core/src/erlang/pattern.rs","lineNumber":314,"sourceCode":"        &mut self,\n        builder: &mut impl ErlangBuilder<Output>,\n        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,","sourceCodeStart":296,"sourceCodeEnd":332,"githubUrl":"https://github.com/gleam-lang/gleam/blob/15b07c783065c92bb016b1b74ed0995a5259850f/compiler-core/src/erlang/pattern.rs#L296-L332","documentation":"An internal compiler assertion in bit-array pattern size codegen: a BitArraySize::Variable was registered in variables_to_add_later with a non-integer AliasedLiteral (e.g. a string or float constant), but segment sizes must be integers. The type checker should have rejected a non-int size before code generation.","triggerScenarios":"Compiling a `<<..:size(var)>>` pattern where `var` aliases a constant whose literal is not an Int, and the type checker failed to flag it.","commonSituations":"Using a string/float constant as a bit-array segment size via an aliased variable; typically indicates a type-checker gap or bug rather than expected behavior.","solutions":["Make the size variable reference an Int constant or literal.","Update gleam — the type checker should reject this case with a proper diagnostic.","File a minimal reproducing module at github.com/gleam-lang/gleam."],"exampleFix":"// before\nconst size: String = \"4\"\nlet assert <<a:size(size)>> = bits\n// after\nconst size: Int = 4\nlet assert <<a:size(size)>> = bits","handlingStrategy":"type-guard","validationCode":"// Ensure size variables are Int constants\nconst size: Int = 8\nassert size is _","typeGuard":"fn is_int_size(v: &ValueConstructor) -> bool {\n    matches!(v.variant, ValueConstructorVariant::ModuleConstant { literal: Constant::Int { .. }, .. })\n}","tryCatchPattern":"let status = Command::new(\"gleam\").args([\"build\"]).status()?;\nif !status.success() { /* handle failure */ }","preventionTips":["Only use Int literals/constants as bit-array segment sizes.","Never alias a String/Float constant into a `size(..)` position.","Run `gleam check` to catch type errors before codegen."],"tags":["compiler","internal","bit-array","type-checking"],"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"}