{"record":{"id":"83d4d3aa16fe1a80","repo":"gleam-lang/gleam","slug":"token-could-not-be-converted-to-binop","errorCode":null,"errorMessage":"Token could not be converted to binop.","messagePattern":"Token could not be converted to binop\\.","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"compiler-core/src/parse.rs","lineNumber":5207,"sourceCode":"            expressions\n        } else {\n            vec1![left, right]\n        };\n        UntypedExpr::Pipeline { expressions }\n    } else {\n        match token_to_binop(&token) {\n            Some(operator) => UntypedExpr::BinOp {\n                location: SrcSpan {\n                    start: left.location().start,\n                    end: right.location().end,\n                },\n                operator,\n                operator_start: token_start,\n                left: Box::new(left),\n                right: Box::new(right),\n            },\n            _ => {\n                panic!(\"Token could not be converted to binop.\")\n            }\n        }\n    }\n}\n\nfn clause_guard_reduction(\n    (start, token, _end): Spanned,\n    left: UntypedClauseGuard,\n    right: UntypedClauseGuard,\n) -> UntypedClauseGuard {\n    let location = SrcSpan {\n        start: left.location().start,\n        end: right.location().end,\n    };\n    let left = Box::new(left);\n    let right = Box::new(right);\n    let operator = token_to_binop(&token).expect(\"Token could not be converted to binop.\");\n    UntypedClauseGuard::BinaryOperator {","sourceCodeStart":5189,"sourceCodeEnd":5225,"githubUrl":"https://github.com/gleam-lang/gleam/blob/15b07c783065c92bb016b1b74ed0995a5259850f/compiler-core/src/parse.rs#L5189-L5225","documentation":"An internal parser panic in `expression_operator_reduction` (compiler-core/src/parse.rs). This function maps an operator token to a binary-operation AST node while building operator-precedence expressions; the `_` arm panics when a token that reached the binop-construction path cannot be converted into a binary operator. It should be unreachable because operator filtering happens earlier in the precedence-climbing loop.","triggerScenarios":"The precedence reducer receives a `Spanned` token in the operator position that is not one of the recognized binary operators (e.g. after a change to the token set or precedence table), so the final match falls through to `_`.","commonSituations":"Seen by Gleam compiler contributors after adding/renaming tokens or operators without updating `expression_operator_reduction`, or by fuzzers feeding pathological token sequences. Not reachable through normal `gleam build` usage of supported syntax.","solutions":["Capture the input program that panics and report it upstream with a minimal repro.","If contributing: add the missing token-to-binop mapping in `expression_operator_reduction` before the `_ => panic!` arm.","Update to the newest gleam-core release; the panic may have been fixed upstream."],"exampleFix":"// before\n_ => {\n    panic!(\"Token could not be converted to binop.\")\n}\n// after\n(token, ..) if is_new_operator(token) => BinOp::NewOperator,\n_ => {\n    panic!(\"Token could not be converted to binop.\")\n}","handlingStrategy":"try-catch","validationCode":"null","typeGuard":"// Rust: assert the token is a known binop token before reduction\nfn is_binop_token(t: &Token) -> bool {\n    matches!(t, Token::Plus | Token::Minus | Token::Star /* ...all binop tokens */)\n}","tryCatchPattern":"// Panic is unrecoverable by design; in tooling wrap parsing in catch_unwind.\nstd::panic::catch_unwind(|| parse_expression(src))","preventionTips":["Keep the precedence table and expression_operator_reduction in sync when adding operators.","Add a unit test per new operator exercising expression_operator_reduction.","Report any panic reached from valid Gleam source as a compiler bug."],"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"}