gleam-lang/gleam · error
segment size that is not int made it through type checking
Error message
segment size that is not int made it through type checking
What it means
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.
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.
Example fix
// before const size: String = "4" let assert <<a:size(size)>> = bits // after const size: Int = 4 let assert <<a:size(size)>> = bits
Defensive patterns
Strategy: type-guard
Validate before calling
// Ensure size variables are Int constants const size: Int = 8 assert size is _
Type guard
fn is_int_size(v: &ValueConstructor) -> bool {
matches!(v.variant, ValueConstructorVariant::ModuleConstant { literal: Constant::Int { .. }, .. })
} Try / catch
let status = Command::new("gleam").args(["build"]).status()?;
if !status.success() { /* handle failure */ } Prevention
- 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.
When it happens
Trigger: Compiling a `<<..:size(var)>>` pattern where `var` aliases a constant whose literal is not an Int, and the type checker failed to flag it.
Common situations: 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.
Understand the failure class
Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.
Related errors
- invalid segment
- invalid pattern inside aliased bit array pattern segment
- invalid size in pattern size segment
- bit array compilation with no choice
- empty bit array test
AI-assisted analysis of gleam-lang/gleam@15b07c7830 (2026-09-14).
Data as JSON: /api/errors/772864842e9b10bb.
Report an issue: GitHub.
Appendix: source
Thrown at compiler-core/src/erlang/pattern.rs:314
&mut self,
builder: &mut impl ErlangBuilder<Output>,
size: &'a TypedBitArraySize,
) {
match size {
BitArraySize::Int {
int_value,
location,
..
} => builder.int_expression(*location, int_value.clone()),
BitArraySize::Block { inner, .. } => self.bit_array_size(builder, inner),
BitArraySize::Variable {
constructor, name, ..
} => match self.variables_to_add_later.get(name) {
Some(AliasedLiteral::Int { value, location }) => {
builder.int_expression(*location, value.clone())
}
Some(_) => panic!("segment size that is not int made it through type checking"),
None => {
let constructor = constructor.as_ref().expect("variable with no constructor");
match &constructor.variant {
ValueConstructorVariant::ModuleConstant { literal, .. } => {
self.generator.inlined_constant(builder, literal);
}
ValueConstructorVariant::LocalVariable { location, .. } => {
builder.variable(*location, &self.generator.local_var_name(location));
}
ValueConstructorVariant::ModuleFn { .. }
| ValueConstructorVariant::Record { .. } => panic!("invalid segment"),
}
}
},
BitArraySize::BinaryOperator {
operator,
left,View on GitHub (pinned to 15b07c7830)