gleam-lang/gleam · error
Type checking ensures there is at least one statement
Error message
Type checking ensures there is at least one statement
What it means
The cross-module function inliner stores inlined statement lists as Vec<TypedStatement> and converts them into the NonEmptyStatements type with try_into().expect("Type checking ensures there is at least one statement") (inline.rs:1026). Gleam function bodies always contain at least one expression after parsing/type-checking, so an empty list here means an internal invariant broke — an internal compiler error (ICE), not something caused by your project configuration.
Source
Thrown at compiler-core/src/inline.rs:1026
self.position = Position::InlinedFunction;
let variables = self.renamed_variables.clone();
// Perform inlining on each of the statements in this function's body,
// potentially inlining parameters and function calls inside this function.
statements.extend(body.into_iter().map(|statement| self.statement(statement)));
// Restore scope
self.inline_variables = inline_variables;
self.position = position;
self.renamed_variables = variables;
// We try to expand this block, so a function which is inlined as a
// single expression does not get wrapped unnecessarily
expand_block(TypedExpr::Block {
location: BLANK_LOCATION,
statements: statements
.try_into()
.expect("Type checking ensures there is at least one statement"),
})
}
fn pipeline(
&mut self,
location: SrcSpan,
first_value: TypedPipelineAssignment,
assignments: Vec<(TypedPipelineAssignment, PipelineAssignmentKind)>,
finally: Box<TypedExpr>,
finally_kind: PipelineAssignmentKind,
) -> TypedExpr {
let first_value = self.pipeline_assignment(first_value);
let assignments = assignments
.into_iter()
.map(|(assignment, kind)| (self.pipeline_assignment(assignment), kind))
.collect();
let finally = self.boxed_expression(finally);
View on GitHub (pinned to 7e623aa83d)
Solutions
- Delete the build cache and rebuild: `rm -rf build && gleam build` — this is the fix for the stale-cache variant.
- Pin the compiler version that previously worked (`gleam-toolchain`/mise/asdf) until you can upgrade to a release with the fix.
- If it reproduces on a clean build, minimize the failing module and report it with the panic backtrace at github.com/gleam-lang/gleam.
- As a workaround, stop the function from being inlined: make it non-trivial or move it out of the cross-module inline path (e.g. avoid marking it for inlining).
Example fix
# before: stale artifacts from an older compiler rm -rf build # forgotten after `gleam` upgrade # after: always clear generated code caches across toolchain changes rm -rf build && gleam clean && gleam build
Defensive patterns
Strategy: try-catch
Try / catch
// Tooling that drives gleam_core's build in-process: isolate ICEs so a
// compiler bug is reportable instead of fatal.
let result = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
build::main(paths, options)
}));
match result {
Ok(Ok(())) => {}
Ok(Err(e)) => eprintln!("gleam error: {e:?}"),
Err(payload) => eprintln!("internal compiler error: {payload:?} — please report with backtrace"),
} Prevention
- Delete `build/` (and CI caches over it) whenever the gleam version changes.
- Pin the compiler version in CI so caches are never reused across toolchain upgrades.
- When an ICE appears, first reproduce on a clean checkout to classify cache-skew vs real bug before reporting.
When it happens
Trigger: Compiling code whose inlinable function body round-trips through the incremental build cache with zero statements — typically a stale/corrupted build directory after a compiler upgrade, or an inliner bug on an unusual expression shape (e.g. a function body that became empty after inlining substitutions).
Common situations: Upgrading gleam versions but keeping the old `build/` directory; CI caches (actions/cache over build/) reused across toolchain updates; exotic pipelines/case expressions exercising inliner edge cases.
Related errors
- Type-checking ensured that the body has at least 1 statement
- Custom type must have at least one definition here
- `panic` expression evaluated.
- Non-UTF8 path in hardlink_dir
- Writing warning to stderr
AI-assisted analysis of gleam-lang/gleam@7e623aa83d (2026-08-17).
Data as JSON: /api/errors/61687e7c05dea61b.
Report an issue: GitHub.