{"record":{"id":"1df8f82ac25e7f58","repo":"gleam-lang/gleam","slug":"type-checking-ensured-that-the-body-has-at-least-1","errorCode":null,"errorMessage":"Type-checking ensured that the body has at least 1 statement","messagePattern":"Type-checking ensured that the body has at least 1 statement","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"compiler-core/src/inline.rs","lineNumber":1838,"sourceCode":"    /// Converts an `InlinableFunction` to an anonymous function, which can then\n    /// be inlined within another function.\n    fn to_anonymous_function(&self) -> (Vec<TypedArg>, Vec1<TypedStatement>) {\n        let parameters = self\n            .parameters\n            .iter()\n            .map(|parameter| parameter.to_typed_arg())\n            .collect();\n\n        let body = self\n            .body\n            .iter()\n            .map(|ast| Statement::Expression(ast.to_expression()))\n            .collect_vec();\n\n        (\n            parameters,\n            body.try_into()\n                .expect(\"Type-checking ensured that the body has at least 1 statement\"),\n        )\n    }\n}\n\n#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]\npub enum InlinableExpression {\n    Case {\n        subjects: Vec<InlinableExpression>,\n        clauses: Vec<InlinableClause>,\n        compiled_case: Box<CompiledCase>,\n        type_: InlinableType,\n    },\n\n    Variable {\n        name: EcoString,\n        constructor: InlinableValueConstructor,\n        type_: InlinableType,\n    },","sourceCodeStart":1820,"sourceCodeEnd":1856,"githubUrl":"https://github.com/gleam-lang/gleam/blob/7e623aa83da3776faee50ca4ab9a6c40124acd95/compiler-core/src/inline.rs#L1820-L1856","documentation":"When the compiler serializes inlinable functions back out of the analysis phase, it converts the stored body statements into the NonEmpty TypedStatements type with body.try_into().expect(\"Type-checking ensured that the body has at least 1 statement\") (inline.rs:1838). Because Gleam grammars require every function body to have at least one expression, an empty body can only come from malformed serialized/cached data — another internal-compiler-error class panic rather than a user mistake.","triggerScenarios":"The InlinableFunction's stored body deserializes to an empty statements vec — corrupted or version-skewed incremental build caches, or a bug in the code that produces InlinableFunction bodies upstream.","commonSituations":"Build directories shared or cached between different gleam versions (CI caches, network filesystems), interrupted builds leaving half-written cache files, or hitting a new inliner regression after upgrading.","solutions":["Clear all build artifacts: `gleam clean && rm -rf build`, then rebuild from scratch.","Reproduce on a single clean checkout to confirm cache vs code: if it still panics, downgrade/upgrade gleam and check the release notes for inliner fixes.","Report the panic with the module source at github.com/gleam-lang/gleam — this expect should never fire given well-formed input.","For embedders running gleam_core in-process, isolate compilation in a subprocess so an ICE cannot take down your host."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Maintainers/embedders of the inliner: validate deserialized bodies before\n// the NonEmpty conversion instead of relying on the expect.\nif body.is_empty() {\n    return Err(corrupt_cache_error(module)); // rebuild this package from source\n}\nlet body: NonEmptyTypedStatements = body.try_into().expect(\"checked non-empty above\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never share or persist `build/` directories between different gleam versions.","Add `gleam clean` to scripts that switch toolchains (mise/asdf/gleam-toolchain hooks).","Treat this panic as data corruption: wipe caches, rebuild, and only then file an upstream issue."],"tags":["panic","internal-compiler-error","inliner","deserialization","nonempty","build-cache"],"backgroundTag":"compiler-internal-error","analyzedSha":"7e623aa83da3776faee50ca4ab9a6c40124acd95","analyzedAt":"2026-08-17T00:07:02.091Z","schemaVersion":2},"datasetVersion":"2026-08-17T04:17:16.089Z"}