gleam-lang/gleam · error
missing guard
Error message
missing guard
What it means
Error "missing guard" thrown in gleam-lang/gleam.
Source
Thrown at compiler-core/src/javascript/decision.rs:902
}
fn decision_guard(
&mut self,
arena: &'doc DocumentArena<'a, 'doc>,
guard: usize,
if_true: &'a Body,
if_false: &'a Decision,
) -> CaseBody<'a, 'doc> {
let DecisionKind::Case { clauses } = &self.kind else {
unreachable!("Guards cannot appear in let assert decision trees")
};
let guard = clauses
.get(guard)
.expect("invalid clause index")
.guard
.as_ref()
.expect("missing guard");
// Before generating the if-else condition we want to generate all the
// assignments that will be needed by the guard condition so we can rest
// assured they are in scope and the guard check can use those.
let guard_variables = guard.referenced_variables();
let (check_bindings, if_true_bindings): (Vec<_>, Vec<_>) = if_true
.bindings
.iter()
.partition(|(variable, _)| guard_variables.contains(variable));
let (check_bindings, check, if_true) = self.inside_new_scope(|this| {
// check_bindings and if_true generation have to be in this scope so that pattern-bound
// variables used in guards don't leak into other case branches (if_false).
let check_bindings = this.variables.bindings_ref_doc(arena, &check_bindings);
let check = this.variables.expression_generator.guard(arena, guard);
// All the other bindings that are not needed by the guard check will
// end up directly in the body of the if clause.
let if_true_bindings = this.variables.bindings_ref_doc(arena, &if_true_bindings);View on GitHub (pinned to 7e623aa83d)
When it happens
Trigger: Thrown at compiler-core/src/javascript/decision.rs:902 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of gleam-lang/gleam@7e623aa83d (2026-08-17).
Data as JSON: /api/errors/2c393e85a126dc0a.
Report an issue: GitHub.