{"record":{"id":"c822f142a1af55bd","repo":"gleam-lang/gleam","slug":"unreachable","errorCode":null,"errorMessage":"unreachable","messagePattern":"unreachable","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"compiler-core/src/javascript/decision.rs","lineNumber":1648,"sourceCode":"                        bytes: expected,\n                    } => {\n                        self.literal_string_segment_bytes_check(arena, value, expected, read_action)\n                    }\n                    BitArrayMatchedValue::LiteralFloat(expected) => {\n                        self.literal_float_segment_bytes_check(arena, value, expected, read_action)\n                    }\n                    BitArrayMatchedValue::LiteralInt {\n                        value: expected, ..\n                    } => self.literal_int_segment_bytes_check(\n                        arena,\n                        value,\n                        expected.clone(),\n                        read_action,\n                    ),\n                    BitArrayMatchedValue::Variable(..)\n                    | BitArrayMatchedValue::Discard(..)\n                    | BitArrayMatchedValue::Assign { .. } => {\n                        panic!(\"unreachable\")\n                    }\n                },\n            },\n\n            // When checking on a tuple there's always going to be a single choice\n            // and the code generation will always skip generating the check for it\n            // as the type system ensures it must match.\n            RuntimeCheck::Tuple { .. } => unreachable!(\"tried generating runtime check for tuple\"),\n\n            // Some variants like `Bool` and `Result` are special cased and checked\n            // in a different way from all other variants.\n            RuntimeCheck::Variant { match_, .. } if variable.type_.is_bool() => {\n                match match_.used_name().as_str() {\n                    \"True\" => value.to_doc(arena),\n                    _ => docvec![arena, EXCLAMATION_MARK_DOCUMENT, value],\n                }\n            }\n","sourceCodeStart":1630,"sourceCodeEnd":1666,"githubUrl":"https://github.com/gleam-lang/gleam/blob/49f8762da595eb3c8f576656a4200a142ca188c9/compiler-core/src/javascript/decision.rs#L1630-L1666","documentation":"Internal invariant panic in `runtime_check` for JavaScript code generation (compiler-core/src/javascript/decision.rs:1648). When generating a runtime check for a bit array segment, the matched value must be a literal-like variant that maps to a check (e.g. int/string); `Variable`, `Discard`, or `Assign` variants require no runtime check, and encountering them in the check-building position is unreachable by construction, so the compiler panics with `\"unreachable\"`.","triggerScenarios":"Compiling a JavaScript-target `case` on a bit array where the decision-tree builder hands an aliased/wildcard segment value into runtime check construction — only possible via a compiler bug in pattern binding classification or a patched build.","commonSituations":"Gleam compiler developers working on the JS backend's bit array case compilation; users of pre-release or forked compilers compiling bit array patterns with aliases/discards to JavaScript; not expected from valid code on stable releases.","solutions":["Upgrade to the latest gleam compiler; this should be unreachable on supported releases.","Work around by restructuring the case: bind aliased segments separately instead of inside the matched segment.","File a bug with the failing pattern, target (JavaScript), and compiler version so the decision-tree builder can be fixed.","Compiler contributors: assert/normalize `BitArrayMatchedValue` variants before constructing `RuntimeCheck`s."],"exampleFix":"// before: alias inside the segment triggers the buggy path (compiler bug)\nlet <<a:size(8) as b>> = bits\n// after: separate the binding\nlet <<a:size(8)>> = bits\nlet b = a","handlingStrategy":"type-guard","validationCode":"// only build runtime checks for checkable matched values\nif matches!(value, BitArrayMatchedValue::Variable(_) | BitArrayMatchedValue::Discard(_) | BitArrayMatchedValue::Assign { .. }) {\n    return Ok(None); // no check needed\n}","typeGuard":"fn needs_runtime_check(v: &BitArrayMatchedValue) -> bool {\n    !matches!(v, BitArrayMatchedValue::Variable(_) | BitArrayMatchedValue::Discard(_) | BitArrayMatchedValue::Assign { .. })\n}","tryCatchPattern":null,"preventionTips":["Filter out variable/discard/assign values before constructing RuntimeChecks","Add JS-target tests for bit array patterns with aliases and discards","Prefer returning no-op docs over panicking in unreachable arms"],"tags":["panic","unreachable","internal-invariant","javascript","bit-array"],"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"}