{"record":{"id":"8fe0163f2b17aa86","repo":"gleam-lang/gleam","slug":"list-has-a-type-argument","errorCode":null,"errorMessage":"list has a type argument","messagePattern":"list has a type argument","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"compiler-core/src/exhaustiveness.rs","lineNumber":966,"sourceCode":"        match collapse_links(self.type_.clone()).as_ref() {\n            Type::Fn { .. } | Type::Var { .. } => BranchMode::Infinite,\n            Type::Named { module, name, .. }\n                if is_prelude_module(module)\n                    && (name == \"Int\"\n                        || name == \"Float\"\n                        || name == \"BitArray\"\n                        || name == \"String\") =>\n            {\n                BranchMode::Infinite\n            }\n\n            Type::Named {\n                module,\n                name,\n                arguments,\n                ..\n            } if is_prelude_module(module) && name == \"List\" => BranchMode::List {\n                inner_type: arguments.first().expect(\"list has a type argument\").clone(),\n            },\n\n            Type::Tuple { elements } => BranchMode::Tuple {\n                elements: elements.clone(),\n            },\n\n            Type::Named {\n                module,\n                name,\n                arguments,\n                inferred_variant,\n                ..\n            } => {\n                let constructors = ConstructorSpecialiser::specialise_constructors(\n                    env.get_constructors_for_type(module, name)\n                        .expect(\"Custom type variants must exist\"),\n                    arguments.as_slice(),\n                    &env.current_module,","sourceCodeStart":948,"sourceCodeEnd":984,"githubUrl":"https://github.com/gleam-lang/gleam/blob/49f8762da595eb3c8f576656a4200a142ca188c9/compiler-core/src/exhaustiveness.rs#L948-L984","documentation":"In exhaustiveness checking, when a match branch's subject type is the prelude `List`, the compiler extracts the element type with `arguments.first().expect(\"list has a type argument\")`. The type system guarantees `List` is always parameterised by exactly one element type, so `arguments` should never be empty; the `expect` enforces that invariant and panics if a `List`-typed `Type::Named` arrives with zero type arguments.","triggerScenarios":"Running exhaustiveness analysis (any `case` expression matching on a list) when the checker sees `Type::Named { name: \"List\", arguments: [] }` — caused by a compiler bug in type instantiation, an improperly constructed type from FFI/external type declarations, or a stale/incompatible build of `gleam_stdlib` type metadata.","commonSituations":"Appears as a compiler panic while compiling `case` expressions over lists, usually after a compiler upgrade or when custom tooling/FFI constructs a `List` type without its type parameter.","solutions":["Simplify/rewrite the `case` expression on the list and rebuild to confirm it is not a cache artifact (`gleam clean` then rebuild)","Upgrade Gleam and ensure `gleam_stdlib` is current (`gleam deps update`) so type metadata matches the compiler's expectations","If reproducible with minimal code, file a compiler bug including the pattern-match that triggers it"],"exampleFix":"// before\nlet l = [1, 2, 3]\ncase l { [] -> 0 | [x, ..] -> x }  // panic on affected versions\n// after (workaround: update compiler/stdlib, or avoid the triggering shape)\nlet l = [1, 2, 3]\ngleam:list.first(l)  // use stdlib helpers while the bug is unresolved","handlingStrategy":"validation","validationCode":"// pre-flight: clean stale artifacts and ensure stdlib matches before compiling\n// gleam clean && gleam deps update && gleam build","typeGuard":null,"tryCatchPattern":"let status = Command::new(\"gleam\").arg(\"build\").status();\nif !status.map(|s| s.success()).unwrap_or(false) {\n    eprintln!(\"build panicked or failed; run `gleam clean` and retry\");\n}","preventionTips":["Run `gleam clean` after compiler upgrades to purge stale type metadata","Keep gleam_stdlib and the compiler versions aligned (gleam deps update)","Avoid custom FFI/type tooling that constructs List types without type parameters"],"tags":["rust","compiler","exhaustiveness","lists","invariant"],"backgroundTag":"internal-invariant-violation","analyzedSha":"49f8762da595eb3c8f576656a4200a142ca188c9","analyzedAt":"2026-09-14T11:14:59.388Z","contentChangedAt":"2026-09-14T11:14:59.388Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}