{"record":{"id":"30b568ea2439d1e4","repo":"gleam-lang/gleam","slug":"tried-to-reduce-bit-array-size-without-2-operands","errorCode":null,"errorMessage":"Tried to reduce bit array size without 2 operands","messagePattern":"Tried to reduce bit array size without 2 operands","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"compiler-core/src/parse.rs","lineNumber":5177,"sourceCode":"\n/// Simple-Precedence-Parser, perform reduction for bit array size expressions\nfn reduce_bit_array_size((_, token, _): Spanned, experession_stack: &mut Vec<BitArraySize<()>>) {\n    let operator = token_to_bit_array_size_operator(&token)\n        .expect(\"only operator tokens are pushed onto the bit array size opstack\");\n    match (experession_stack.pop(), experession_stack.pop()) {\n        (Some(right), Some(left)) => {\n            let location = SrcSpan {\n                start: left.location().start,\n                end: right.location().end,\n            };\n            experession_stack.push(BitArraySize::BinaryOperator {\n                left: Box::new(left),\n                right: Box::new(right),\n                operator,\n                location,\n            });\n        }\n        _ => panic!(\"Tried to reduce bit array size without 2 operands\"),\n    }\n}\n\nfn expression_operator_reduction(\n    (token_start, token, _token_end): Spanned,\n    left: UntypedExpr,\n    right: UntypedExpr,\n) -> UntypedExpr {\n    if token == Token::Pipe {\n        let expressions = if let UntypedExpr::Pipeline { mut expressions } = left {\n            expressions.push(right);\n            expressions\n        } else {\n            vec1![left, right]\n        };\n        UntypedExpr::Pipeline { expressions }\n    } else {\n        match token_to_binop(&token) {","sourceCodeStart":5159,"sourceCodeEnd":5195,"githubUrl":"https://github.com/gleam-lang/gleam/blob/15b07c783065c92bb016b1b74ed0995a5259850f/compiler-core/src/parse.rs#L5159-L5195","documentation":"This is an internal compiler panic in Gleam's parser, not a user-facing diagnostic. `reduce_bit_array_size` (compiler-core/src/parse.rs) collapses a binary expression that combines two bit-array size operands, and the match arm `_` should be unreachable. It fires when the parser hands the reducer something other than the two-operand expressions it expects, indicating a parser bug or an unhandled token/operator shape.","triggerScenarios":"Calling `reduce_bit_array_size` with a left/right AST node or operator that is not one of the handled variants — i.e. any fall-through `_` case in the match over expression/operator shapes while parsing a bit array size segment like `<<x:size(N-1)>>`.","commonSituations":"Developers hit this only when modifying the Gleam parser (adding a new operator or expression variant to bit-array sizes without extending the reducer), or when fuzzing/parsing malformed input that reaches an unhandled arm. End users of the gleam CLI (`gleam add`, etc.) never trigger it directly.","solutions":["Reproduce with the offending snippet and file a bug at the gleam repository (compiler-core/src/parse.rs, reduce_bit_array_size) with the source that panicked.","If you are a contributor: extend the match in `reduce_bit_array_size` to handle the new expression/operator variant instead of falling through to `_`.","Upgrade Gleam to the latest version in case the panic was already fixed."],"exampleFix":"// before\n_ => panic!(\"Tried to reduce bit array size without 2 operands\"),\n// after\nUntypedExpr::BitArraySizeConcat { .. } => { /* handle new variant */ }\n_ => panic!(\"Tried to reduce bit array size without 2 operands\"),","handlingStrategy":"try-catch","validationCode":"null","typeGuard":"// Rust: match exhaustively before calling the reducer\nmatch (&left, &operator, &right) {\n    (UntypedExpr::BitArraySizeInt { .. }, _, _) => {},\n    _ => panic/return Err(\"unsupported bit array size operand\"),\n}","tryCatchPattern":"// Panics are not catchable in idiomatic Rust; fix the parser arms or use catch_unwind around parsing in tooling.\nstd::panic::catch_unwind(|| parse(input))","preventionTips":["Never call internal parse:: reduction functions directly; go through the public parser API.","When adding a new bit-array size expression variant, update every match in reduce_bit_array_size.","Run the parser fuzz target after token/AST changes."],"tags":["rust","parser","panic","internal-invariant"],"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"}