{"record":{"id":"6194eae283f89392","repo":"gleam-lang/gleam","slug":"invalid-segment","errorCode":null,"errorMessage":"invalid segment","messagePattern":"invalid segment","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"compiler-core/src/erlang/pattern.rs","lineNumber":325,"sourceCode":"\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,\n            } => {\n                let operator = match operator {\n                    IntOperator::Add => \"+\",\n                    IntOperator::Subtract => \"-\",\n                    IntOperator::Multiply => \"*\",\n                    IntOperator::Divide => {\n                        return self.bit_array_size_divide(location, builder, left, right, \"div\");\n                    }\n                    IntOperator::Remainder => {","sourceCodeStart":307,"sourceCodeEnd":343,"githubUrl":"https://github.com/gleam-lang/gleam/blob/15b07c783065c92bb016b1b74ed0995a5259850f/compiler-core/src/erlang/pattern.rs#L307-L343","documentation":"An internal compiler assertion in bit-array size codegen: a BitArraySize::Variable with no resolvable constant literal resolved to a ModuleFn or Record value constructor instead of a LocalVariable or ModuleConstant. Bit-array segment sizes can only be integers, local variables, or constants, so this resolution is invalid and should have been caught by the type checker.","triggerScenarios":"Compiling a `<<..:size(name)>>` pattern where `name` refers to a function or type constructor rather than an int value/constant, and the type checker failed to reject it.","commonSituations":"Mistakenly using a function name or record constructor as a bit-array segment size; reveals a type-checker hole rather than user-facing behavior.","solutions":["Use an integer variable, literal, or Int constant as the segment size instead.","Update gleam to get the proper type-checker diagnostic for this mistake.","Report the minimal reproducer to github.com/gleam-lang/gleam."],"exampleFix":"// before\nfn two() { 2 }\nlet assert <<a:size(two)>> = bits\n// after\nlet assert <<a:size(2)>> = bits","handlingStrategy":"type-guard","validationCode":"// Verify the size name refers to an Int value, not a function or type\nconst n: Int = 4\nlet assert <<a:size(n)>> = bits","typeGuard":"fn valid_size_value(v: &ValueConstructor) -> bool {\n    matches!(v.variant,\n        ValueConstructorVariant::LocalVariable { .. } |\n        ValueConstructorVariant::ModuleConstant { .. })\n}","tryCatchPattern":"let status = Command::new(\"gleam\").args([\"build\"]).status()?;\nif !status.success() { /* handle failure */ }","preventionTips":["Never pass function names or record constructors as segment sizes.","Use integer literals or Int constants in `size(..)` patterns.","Report checker gaps to the gleam repo."],"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"}