{"record":{"id":"b53f8081b51a2ae1","repo":"gleam-lang/gleam","slug":"unknown-labels-first-label","errorCode":null,"errorMessage":"Unknown labels first label","messagePattern":"Unknown labels first label","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"compiler-core/src/error.rs","lineNumber":2818,"sourceCode":"                .cloned()\n                .collect();\n\n            let title = if unknown.len() > 1 {\n                \"Unknown labels\"\n            } else {\n                \"Unknown label\"\n            }\n            .into();\n\n            let mut labels = unknown.iter().map(|(label, location)| {\n                let text =\n                    did_you_mean(label, &other_labels).unwrap_or_else(|| \"Unexpected label\".into());\n                Label {\n                    text: Some(text),\n                    span: *location,\n                }\n            });\n            let label = labels.next().expect(\"Unknown labels first label\");\n            let extra_labels = labels\n                .map(|label| ExtraLabel {\n                    src_info: None,\n                    label,\n                })\n                .collect();\n            let text = if valid.is_empty() {\n                \"This constructor does not accept any labelled arguments.\".into()\n            } else if other_labels.is_empty() {\n                \"You have already supplied all the labelled arguments that this\nconstructor accepts.\"\n                    .into()\n            } else {\n                let mut label_text = String::from(\"It accepts these labels:\\n\");\n                for label in other_labels.iter().sorted() {\n                    label_text.push_str(\"\\n    \");\n                    label_text.push_str(label);\n                }","sourceCodeStart":2800,"sourceCodeEnd":2836,"githubUrl":"https://github.com/gleam-lang/gleam/blob/49f8762da595eb3c8f576656a4200a142ca188c9/compiler-core/src/error.rs#L2800-L2836","documentation":"When the compiler reports unknown record-constructor (labelled) argument errors, it builds a `Label` iterator over the mismatched labels and unconditionally takes the first one: `labels.next().expect(\"Unknown labels first label\")`. The invariant is that the error being rendered was only constructed because at least one unknown label existed, so the iterator must be non-empty; if the label list was emptied or never populated, this `expect` panics during diagnostic construction.","triggerScenarios":"Rendering an unknown-labels diagnostic (e.g. calling a constructor/function with a wrong or missing label) when the underlying `UnknownLabels` error carries zero labels — a compiler-internal inconsistency, e.g. a bug in how unknown labels are collected in `analyse.rs` / error construction.","commonSituations":"Users see this as an ICE while compiling code with mislabelled constructor or function arguments on an affected Gleam version; typically right after calling a custom type constructor with an argument label the type does not define.","solutions":["Fix the mislabelled constructor call in your Gleam code — check the type definition and use the exact declared labels (or remove labels if the type has none)","Reduce the snippet and file a compiler bug if the panic occurs on code that looks correct","Upgrade Gleam to the latest release where label diagnostics have been reworked (label_references/label_definitions tracking)"],"exampleFix":"// before (Gleam)\nlet pet = Dog(name: \"Rex\", legs: 4)  // `legs` is not a label of Dog\n// after\nlet pet = Dog(name: \"Rex\")            // use only labels declared on the constructor","handlingStrategy":"fallback","validationCode":"// Gleam-side: verify constructor argument labels before calling\ncase Dog { Dog(..) -> io.println(\"check labels against the type definition\") }","typeGuard":null,"tryCatchPattern":"gleam build 2>err.log || echo \"ICE while reporting labels — inspect err.log, reduce snippet, file a bug\"","preventionTips":["Use exactly the labels declared on the custom type constructor; remove labels if none are declared","Keep the compiler and stdlib up to date","If an ICE appears on seemingly correct code, minimize and report it — the zero-label error state is a compiler bug"],"tags":["rust","compiler","labels","diagnostics","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"}