gleam-lang/gleam · error · ErrorType
ErrorType::ConflictingUnitOptions
Error message
ErrorType::ConflictingUnitOptions
What it means
ErrorType::ConflictingUnitOptions is raised when a bit array segment declares the unit option more than once. A segment accepts at most one 'unit:n' option, which defines the default unit size for the segment.
Solutions
- Keep only one unit option per segment
- If you wanted a total size of size*unit, express that with a single size and single unit
- Review generated option lists for duplicated unit emissions
Example fix
// before <<raw:bytes-unit(8)-unit(1)>> // after <<raw:bytes-unit(8)>>
Defensive patterns
Strategy: validation
Validate before calling
// At most one `unit:` option per segment
fn unit_option_count(spec: String) -> Int {
string.split(spec, "unit:") |> list.length |> int.subtract(1)
} Prevention
- One unit per segment; combine with a single size to get the total
- Check code generators that emit segment options for duplicated unit output
- Keep option lists short and hand-reviewed per segment
When it happens
Trigger: Writing a segment like <<x:bytes-unit(8)-unit(1)>> or duplicating the unit option through generated/copy-pasted option lists; type_options finds categories.unit already set.
Common situations: Copy-paste of option chains between segments; templated code generation emitting unit twice; misunderstanding that unit multiplies with size and trying to stack two units.
Related errors
- ErrorType::ConflictingEndiannessOptions
- ErrorType::ConflictingSignednessOptions
- ErrorType::ConflictingSizeOptions
- This is an extra type specifier
- ErrorType::ConstantSizeNotPositive
AI-assisted analysis of gleam-lang/gleam@15b07c7830 (2026-09-14).
Data as JSON: /api/errors/26cec3b7517a8e26.
Report an issue: GitHub.
Appendix: source
Thrown at compiler-core/src/bit_array.rs:192
},
option.location(),
);
} else {
categories.endian = Some(option);
}
}
Size { .. } => {
if categories.size.is_some() {
return err(ErrorType::ConflictingSizeOptions, option.location());
} else {
categories.size = Some(option);
}
}
Unit { .. } => {
if categories.unit.is_some() {
return err(ErrorType::ConflictingUnitOptions, option.location());
} else {
categories.unit = Some(option);
}
}
}
}
// Some options are not allowed in value mode
if mode == TypeOptionsMode::Expression {
match categories {
SegmentOptionCategories {
signed: Some(opt), ..
}
| SegmentOptionCategories {
type_: Some(opt @ Bytes { .. }),
..
} => return err(ErrorType::OptionNotAllowedInValue, opt.location()),
_ => (),View on GitHub (pinned to 15b07c7830)