{"record":{"id":"d9b7320c68972b44","repo":"gleam-lang/gleam","slug":"unknown-pattern-id","errorCode":null,"errorMessage":"unknown pattern id","messagePattern":"unknown pattern id","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"compiler-core/src/exhaustiveness.rs","lineNumber":2401,"sourceCode":"impl<'a> Compiler<'a> {\n    fn new(environment: &'a Environment<'a>, variable_id: usize, patterns: Arena<Pattern>) -> Self {\n        Self {\n            environment,\n            patterns,\n            variable_id,\n            diagnostics: Diagnostics {\n                missing: false,\n                reachable: HashSet::new(),\n                match_impossible_variants: HashSet::new(),\n                match_impossible_segments: HashMap::new(),\n            },\n        }\n    }\n\n    fn pattern(&mut self, pattern_id: Id<Pattern>) -> &mut Pattern {\n        self.patterns\n            .get_mut(pattern_id)\n            .expect(\"unknown pattern id\")\n    }\n\n    /// Returns a new fresh variable (i.e. guaranteed to have a unique `variable_id`)\n    /// with the given type.\n    ///\n    fn fresh_variable(&mut self, type_: Arc<Type>) -> Variable {\n        let var = Variable::new(self.variable_id, type_);\n        self.variable_id += 1;\n        var\n    }\n\n    fn mark_as_reached(&mut self, branch: &Branch) {\n        let _ = self\n            .diagnostics\n            .reachable\n            .insert((branch.clause_index, branch.alternative_index));\n    }\n","sourceCodeStart":2383,"sourceCodeEnd":2419,"githubUrl":"https://github.com/gleam-lang/gleam/blob/49f8762da595eb3c8f576656a4200a142ca188c9/compiler-core/src/exhaustiveness.rs#L2383-L2419","documentation":"This is a Rust panic from an `expect` on a HashMap lookup in the Gleam compiler's exhaustiveness checker (`decision::reachability` pattern store). The compiler tried to fetch a Pattern by its arena Id, and the id was not present in the interner map. It is an internal invariant violation, not something pattern-matching user code did wrong semantically.","triggerScenarios":"Calling `DecisionReachability::pattern(pattern_id)` (directly or via `register`/check building) with an `Id<Pattern>` that was never inserted into `self.patterns`, or that came from a different pattern-store instance (e.g. ids created by another compilation of the same function).","commonSituations":"Developers hit this while hacking on the Gleam compiler itself: refactoring how patterns are registered, reusing pattern ids across two exhaustiveness runs, or building a `RuntimeCheckKind` from patterns that were never passed through `register`.","solutions":["Ensure every `Id<Pattern>` you use was produced by the same `register`/pattern-store instance that is doing the lookup.","Check for off-by-one or copied ids: regenerate the id via `register` instead of reusing a stale one.","Replace `.expect` with a graceful error (Error::Bug / todo) if the id can legitimately be absent, and file a Gleam compiler bug with the crashing module if it is not your code."],"exampleFix":"// before\nlet pattern = self.patterns.get_mut(pattern_id).expect(\"unknown pattern id\");\n// after\nlet pattern = self.patterns.get_mut(pattern_id).unwrap_or_else(|| {\n    panic!(\"unknown pattern id {:?} in store of {} patterns\", pattern_id, self.patterns.len())\n});","handlingStrategy":"validation","validationCode":"// Before relying on an Id<Pattern>, confirm it exists in the store:\nassert!(store.patterns.contains_key(&pattern_id), \"pattern id not registered in this store\");","typeGuard":"fn is_registered(store: &PatternStore, id: Id<Pattern>) -> bool {\n    store.patterns.contains_key(&id)\n}","tryCatchPattern":"// Rust panics cannot be caught idiomaticly; catch at the binary boundary:\nlet result = std::panic::catch_unwind(|| compile_case(module));\nmatch result { Ok(v) => v, Err(_) => report_bug(\"unknown pattern id\") }","preventionTips":["Never carry Id<Pattern> values across two exhaustiveness-checker instances.","Always obtain ids from `register`, never synthesize or copy them.","Convert expects into typed Bug errors in compiler PRs."],"tags":["rust","compiler","panics","exhaustiveness"],"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"}