{"record":{"id":"502cae2f527b8049","repo":"gleam-lang/gleam","slug":"custom-type-constructor-must-have-custom-type-kind","errorCode":null,"errorMessage":"Custom type constructor must have custom type kind","messagePattern":"Custom type constructor must have custom type kind","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"compiler-core/src/exhaustiveness/missing_patterns.rs","lineNumber":186,"sourceCode":"                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                    })\n                    .collect();\n\n                Term::Variant {\n                    variable,\n                    name,","sourceCodeStart":168,"sourceCodeEnd":204,"githubUrl":"https://github.com/gleam-lang/gleam/blob/15b07c783065c92bb016b1b74ed0995a5259850f/compiler-core/src/exhaustiveness/missing_patterns.rs#L168-L204","documentation":"After resolving the named type, `check_to_term` looks up the type's constructors via `environment.get_constructors_for_type(&module, &name).expect(\"Custom type constructor must have custom type kind\")`. It panics when the environment has no constructor registration for that type, meaning the type in the check isn't a custom type with registered variants. This is an internal consistency check between type checking and the exhaustiveness environment.","triggerScenarios":"A check references a variable whose named type was never registered in the exhaustiveness `Environment` (e.g. checking against a type that isn't a custom type, or the environment was built without constructors for parameterised/aliased types).","commonSituations":"Encountered by compiler contributors when types get desugared or aliased before reaching exhaustiveness so the name no longer matches registered constructors, or in fuzzed inputs combining generics with case matching.","solutions":["Ensure constructor registration covers all named types used in checks (update `get_constructors_for_type` callers / environment population)","Check for alias unfolding: resolve type aliases to their underlying custom type before lookup","Debug-print `module`/`name` at the panic site to find which type lacks registration","End users: file a compiler bug with the reproducing module"],"exampleFix":"// before\n.expect(\"Custom type constructor must have custom type kind\")\n// after\n.unwrap_or_else(|| panic!(\"no constructors registered for type {}::{} in exhaustiveness environment\", module, name))","handlingStrategy":"validation","validationCode":"if environment.get_constructors_for_type(&module, &name).is_none() {\n    return Err(Error::TypeMissingConstructorRegistration { module, name });\n}","typeGuard":"fn constructors_registered(env: &Environment, t: &Type) -> bool {\n    t.named_type_name().map_or(false, |(m, n)| env.get_constructors_for_type(&m, &n).is_some())\n}","tryCatchPattern":null,"preventionTips":["Register constructors for every named type when building the exhaustiveness environment","Resolve type aliases before lookup","Log module/name in panic messages for faster triage"],"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"}