gleam-lang/gleam · error · ErrorType
ErrorType::OptionNotAllowedInValue
Error message
ErrorType::OptionNotAllowedInValue
What it means
ErrorType::OptionNotAllowedInValue: after collecting segment options, type_options rejects options that are only legal in patterns when the segment appears in a bit array VALUE expression. Specifically a signed/unsigned option, or a bare bytes type option in this position, is not permitted in a value.
Solutions
- Remove the signed/unsigned option from value expressions; signedness only affects matching
- Use an explicit sized int/float type in the value instead of the disallowed option
- If the code was intended as a pattern, move it into a case/let-assert pattern position
Example fix
// before (value) let x = <<n:int-signed>> // after let x = <<n:int>>
Defensive patterns
Strategy: validation
Validate before calling
// signedness (and bare bytes in this position) only belongs in patterns, not values
fn is_value_with_signedness(segment_spec: String, in_pattern: Bool) -> Bool {
!in_pattern
&& { string.contains(segment_spec, "signed") || string.contains(segment_spec, "unsigned") }
} Prevention
- Treat signed/unsigned as pattern-only modifiers
- Copy pattern segments into expressions only after stripping match-specific options
- When a value segment needs interpretation, decode it in code rather than via pattern options
When it happens
Trigger: Constructing a bit array value with a segment carrying signed/unsigned (e.g. <<x:int-signed>>) or a Bytes option that the value-mode post-check disallows (categories.signed set, or type_ is Bytes in value mode).
Common situations: Assuming signedness is an encoding concern in value construction (it only matters for pattern matching); copying a pattern segment verbatim into an expression.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- ErrorType::ConflictingEndiannessOptions
- ErrorType::ConflictingSignednessOptions
- ErrorType::ConflictingSizeOptions
- ErrorType::ConflictingUnitOptions
- ErrorType::ConstantSizeNotPositive
AI-assisted analysis of gleam-lang/gleam@15b07c7830 (2026-09-14).
Data as JSON: /api/errors/bce54c12aecafef5.
Report an issue: GitHub.
Appendix: source
Thrown at compiler-core/src/bit_array.rs:209
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()),
_ => (),
}
}
// All but the last segment in a pattern must have an exact size
if must_have_size
&& let SegmentOptionCategories {
type_: Some(opt @ (Bytes { .. } | Bits { .. })),
size: None,
..
} = categories
{
return err(ErrorType::SegmentMustHaveSize, opt.location());
}
// Endianness is only valid for int, utf16, utf16_codepoint, utf32,
// utf32_codepoint and float
match categories {View on GitHub (pinned to 15b07c7830)