{"record":{"id":"5521fa49ebc719da","repo":"gleam-lang/gleam","slug":"todo-constants-should-not-reach-code-generation","errorCode":null,"errorMessage":"todo constants should not reach code generation","messagePattern":"todo constants should not reach code generation","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"compiler-core/src/javascript/expression.rs","lineNumber":2862,"sourceCode":"                | BinOp::MultFloat\n                | BinOp::DivInt\n                | BinOp::DivFloat\n                | BinOp::RemainderInt => {\n                    unreachable!(\"invalid constant operator made it to code generation\")\n                }\n\n                BinOp::Concatenate => {\n                    let left = self.constant_expression(arena, context, left);\n                    let right = self.constant_expression(arena, context, right);\n                    docvec![arena, left, SPACE_PLUS_SPACE_DOCUMENT, right]\n                }\n            },\n\n            Constant::RecordUpdate { .. } => {\n                panic!(\"record updates should not reach code generation\")\n            }\n            Constant::Todo { .. } => {\n                panic!(\"todo constants should not reach code generation\")\n            }\n            Constant::Invalid { .. } => {\n                panic!(\"invalid constants should not reach code generation\")\n            }\n        }\n    }\n\n    fn constant_bit_array(\n        &mut self,\n        arena: &'doc DocumentArena<'a, 'doc>,\n        segments: &'a [TypedConstantBitArraySegment],\n        context: Context,\n    ) -> Document<'a, 'doc> {\n        self.tracker.bit_array_literal_used = true;\n        let segments_array = array(\n            arena,\n            segments.iter().filter_map(|segment| {\n                let value = match context {","sourceCodeStart":2844,"sourceCodeEnd":2880,"githubUrl":"https://github.com/gleam-lang/gleam/blob/49f8762da595eb3c8f576656a4200a142ca188c9/compiler-core/src/javascript/expression.rs#L2844-L2880","documentation":"`Constant::Todo` (a `todo` placeholder used in constant position) is not translatable to JavaScript; the generator panics to signal it should never see one. Earlier compiler phases are expected to reject or replace todo constants before codegen.","triggerScenarios":"A constant expression containing `todo` reaches the JavaScript backend's `constant_expression`, e.g. `pub const x = todo` where type inference failed to reject it first.","commonSituations":"Stubbing out a module constant with `todo` during prototyping; compiler regression letting a Todo constant slip through validation.","solutions":["Replace `todo` in the constant with a concrete value.","Turn the constant into a function returning the value so `todo` is allowed in the body.","If the code should already have been rejected with a proper error, report a compiler bug."],"exampleFix":"// before\npub const api_key = todo\n// after\npub const api_key = \"changeme\"","handlingStrategy":"validation","validationCode":"// reject todo in constant position before codegen\nif let Constant::Todo { location, .. } = constant {\n    return Err(error_todo_constant(location));\n}","typeGuard":"fn is_resolved_constant(c: &Constant) -> bool {\n    !matches!(c, Constant::Todo { .. })\n}","tryCatchPattern":"match std::panic::catch_unwind(|| codegen_constant(&c)) {\n    Ok(doc) => doc,\n    Err(_) => emit_internal_error_diagnostic(),\n}","preventionTips":["Replace `todo` in constants with concrete values before building.","Use a function body instead of a constant when you need `todo` placeholders.","Search code for `= todo` in const positions during refactors."],"tags":["compiler","panic","code-generation","todo"],"backgroundTag":"unsupported-operation","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"}