{"record":{"id":"524abff338b1903d","repo":"gleam-lang/gleam","slug":"should-be-a-named-type","errorCode":null,"errorMessage":"Should be a named type","messagePattern":"Should be a named type","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"compiler-core/src/exhaustiveness/missing_patterns.rs","lineNumber":181,"sourceCode":"            | RuntimeCheck::String { .. }\n            | RuntimeCheck::BitArray { .. }\n            | RuntimeCheck::StringPrefix { .. } => Term::Infinite { variable },\n\n            RuntimeCheck::Tuple { elements, .. } => Term::Tuple {\n                variable,\n                elements: elements.clone(),\n            },\n\n            RuntimeCheck::Variant {\n                index,\n                fields,\n                labels,\n                ..\n            } => {\n                let (module, name) = variable\n                    .type_\n                    .named_type_name()\n                    .expect(\"Should be a named type\");\n\n                let name = self\n                    .environment\n                    .get_constructors_for_type(&module, &name)\n                    .expect(\"Custom type constructor must have custom type kind\")\n                    .variants\n                    .get(*index)\n                    .expect(\"Custom type constructor exist for type\")\n                    .name\n                    .clone();\n\n                let fields = fields\n                    .iter()\n                    .enumerate()\n                    .map(|(index, variable)| VariantField {\n                        label: labels.get(&index).cloned(),\n                        variable: variable.clone(),\n                    })","sourceCodeStart":163,"sourceCodeEnd":199,"githubUrl":"https://github.com/gleam-lang/gleam/blob/15b07c783065c92bb016b1b74ed0995a5259850f/compiler-core/src/exhaustiveness/missing_patterns.rs#L163-L199","documentation":"`check_to_term` converts a type-checked decision-tree `check` back into a pattern term. For constructor checks it derives the type's `(module, name)` via `named_type_name().expect(\"Should be a named type\")`, panicking when the variable's type is not a named (custom) type — e.g. it is a function, tuple, or generic type. The invariant is that only constructor checks on named custom types reach this code path.","triggerScenarios":"`add_missing_patterns_after_check` processing a check whose subject variable has a non-named type (tuple, function type, type variable) — usually after a change to how checks are generated for tuples or parameterised types.","commonSituations":"Hit by Gleam compiler contributors after introducing a new check kind (e.g. tuple checks) that flows into `check_to_term` without being matched before the constructor branch.","solutions":["Match tuple/other check kinds explicitly before the constructor branch in `check_to_term` so only named-type constructor checks hit this code","Verify `type_.named_type_name()` is valid by inspecting the variable's type in a debug build backtrace","If a new type representation (e.g. unlabelled types change) broke the invariant, update the handling accordingly","End users: file a compiler bug with the pattern-match that produces wrong/missing pattern diagnostics"],"exampleFix":"// before\nlet (module, name) = variable.type_.named_type_name().expect(\"Should be a named type\");\n// after\nlet (module, name) = variable.type_.named_type_name().unwrap_or_else(|| {\n    panic!(\"check_to_term on non-named type: {:?}\", variable.type_)\n});","handlingStrategy":"type-guard","validationCode":"if variable.type_.named_type_name().is_none() {\n    return Err(Error::CheckOnNonNamedType);\n}","typeGuard":"let Some((module, name)) = variable.type_.named_type_name() else { return Ok(Term::Variable(variable.clone())); };","tryCatchPattern":null,"preventionTips":["Match all check kinds before the constructor branch in check_to_term","Add a debug assertion that constructor checks only carry named types","Extend tests whenever a new check variant is added"],"tags":["rust","compiler","pattern-matching","panic"],"backgroundTag":"internal-invariant-violation","analyzedSha":"15b07c783065c92bb016b1b74ed0995a5259850f","analyzedAt":"2026-09-14T11:14:59.388Z","contentChangedAt":"2026-09-14T11:14:59.388Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}