{"record":{"id":"500f0fa2b9f9d8ca","repo":"gleam-lang/gleam","slug":"invalid-pattern-inside-aliased-bit-array-pattern-segment","errorCode":null,"errorMessage":"invalid pattern inside aliased bit array pattern segment","messagePattern":"invalid pattern inside aliased bit array pattern segment","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"compiler-core/src/erlang/pattern.rs","lineNumber":417,"sourceCode":"            // code for a variable pattern with the wanted name and call it a day\n            Pattern::Discard { .. } => {\n                builder.variable_pattern(\n                    *location,\n                    &self.generator.new_erlang_variable(name, *location),\n                );\n                return;\n            }\n\n            Pattern::Variable { .. }\n            | Pattern::BitArraySize(_)\n            | Pattern::Assign { .. }\n            | Pattern::List { .. }\n            | Pattern::Constructor { .. }\n            | Pattern::Tuple { .. }\n            | Pattern::BitArray { .. }\n            | Pattern::StringPrefix { .. }\n            | Pattern::Invalid { .. } => {\n                panic!(\"invalid pattern inside aliased bit array pattern segment\")\n            }\n        };\n\n        let _ = self\n            .variables_to_add_later\n            .insert(name.clone(), aliased_value);\n        self.pattern(builder, pattern);\n    }\n\n    fn bit_array_pattern_segment_size<Output>(\n        &mut self,\n        builder: &mut impl ErlangBuilder<Output>,\n        segment: &'a TypedPatternBitArraySegment,\n    ) {\n        let Some(size) = segment.size() else {\n            builder.bit_array_segment_default_size();\n            return;\n        };","sourceCodeStart":399,"sourceCodeEnd":435,"githubUrl":"https://github.com/gleam-lang/gleam/blob/15b07c783065c92bb016b1b74ed0995a5259850f/compiler-core/src/erlang/pattern.rs#L399-L435","documentation":"An internal compiler assertion raised while generating code for an aliased bit-array pattern segment (`<<x:size(n) as name>>`): the value bound with `as` is a pattern kind that cannot appear in that position (list, constructor, tuple, bit array, string prefix, or invalid pattern). Only simple variable-like patterns are legal there, and the type checker should have rejected anything else.","triggerScenarios":"Compiling a bit-array segment whose `as` alias binds a complex pattern (e.g. `<<a:size(8) as [b, c]>>`) that the type checker failed to reject.","commonSituations":"Attempting to destructure with a complex pattern after `as` in a bit-array pattern; user error that should surface as a type error but instead panics due to a checking gap.","solutions":["Bind the alias to a plain variable name, then destructure separately.","Update gleam so this mistake produces a proper diagnostic instead of a panic.","Report the minimal example at github.com/gleam-lang/gleam."],"exampleFix":"// before\nlet assert <<a:size(8) as [b, c]>> = bits\n// after\nlet assert <<a:size(8) as pair>> = bits\nlet [b, c] = pair","handlingStrategy":"validation","validationCode":"// Only alias to a plain variable in bit-array patterns\nlet assert <<a:size(8) as pair>> = bits // OK\n// reject: as [b, c], as #(x, y), etc.","typeGuard":"fn is_simple_alias(p: &TypedPattern) -> bool {\n    matches!(p, TypedPattern::Variable { .. })\n}","tryCatchPattern":"let status = Command::new(\"gleam\").args([\"build\"]).status()?;\nif !status.success() { /* handle failure */ }","preventionTips":["Bind `as` aliases to a single variable name only.","Destructure the aliased value in a separate statement.","Keep gleam updated for a proper diagnostic on complex aliases."],"tags":["compiler","internal","bit-array","pattern-matching"],"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"}