{"record":{"id":"076f851da0747609","repo":"gleam-lang/gleam","slug":"invalid-patterns-should-not-reach-code-generation","errorCode":null,"errorMessage":"invalid patterns should not reach code generation","messagePattern":"invalid patterns should not reach code generation","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"compiler-core/src/erlang/pattern.rs","lineNumber":290,"sourceCode":"\n            Pattern::BitArray {\n                segments, location, ..\n            } => {\n                let bit_array = builder.start_bit_array_pattern(*location);\n                for segment in segments {\n                    builder.bit_array_segment(segment.location);\n                    self.bit_array_pattern_segment_value(builder, segment);\n                    self.bit_array_pattern_segment_size(builder, segment);\n                    self.generator\n                        .bit_array_segment_specifiers(builder, segment);\n                }\n                builder.end_bit_array_pattern(bit_array);\n            }\n\n            Pattern::BitArraySize(size) => self.bit_array_size(builder, size),\n\n            Pattern::Invalid { .. } => {\n                panic!(\"invalid patterns should not reach code generation\")\n            }\n        }\n    }\n\n    fn bit_array_size<Output>(\n        &mut self,\n        builder: &mut impl ErlangBuilder<Output>,\n        size: &'a TypedBitArraySize,\n    ) {\n        match size {\n            BitArraySize::Int {\n                int_value,\n                location,\n                ..\n            } => builder.int_expression(*location, int_value.clone()),\n            BitArraySize::Block { inner, .. } => self.bit_array_size(builder, inner),\n\n            BitArraySize::Variable {","sourceCodeStart":272,"sourceCodeEnd":308,"githubUrl":"https://github.com/gleam-lang/gleam/blob/15b07c783065c92bb016b1b74ed0995a5259850f/compiler-core/src/erlang/pattern.rs#L272-L308","documentation":"An internal compiler assertion: a Pattern::Invalid node reached the Erlang pattern code generator. Invalid patterns are error-recovery placeholders created by the parser/type checker after reporting a syntax or type error; they must be filtered out before code generation.","triggerScenarios":"Generating code for a function/clause whose patterns include an invalid pattern (one that already produced an error diagnostic) instead of compilation aborting earlier.","commonSituations":"Compiling a module that contains a malformed pattern the compiler already flagged; the panic typically appears together with the real error message, or alone when error recovery is buggy.","solutions":["Fix the pattern errors the compiler reported earlier in the file.","Update gleam to the latest version (error-recovery bug may be fixed).","File a minimal reproducer at github.com/gleam-lang/gleam if the panic occurs without a prior diagnostic."],"exampleFix":"// before\nlet assert Ok(x) = result\n  | _ -> .. // malformed clause\n// after\nlet assert Ok(x) = result","handlingStrategy":"validation","validationCode":"// Validate patterns parse/type-check before building\ngleam check || exit 1","typeGuard":"match pattern { Pattern::Invalid { .. } => Err(\"invalid pattern\"), _ => Ok(()) }","tryCatchPattern":"let status = Command::new(\"gleam\").args([\"build\"]).status()?;\nif !status.success() { /* read compiler diagnostics */ }","preventionTips":["Fix all syntax/type errors in pattern matches before rebuilding.","Don't ignore earlier diagnostics — this panic is downstream of a rejected pattern.","Keep gleam updated; error-recovery panics are frequently fixed."],"tags":["compiler","internal","pattern-matching","codegen"],"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"}