{"record":{"id":"c4d79eb2fc49a9bc","repo":"gleam-lang/gleam","slug":"record-updates-should-not-reach-code-generation-expression","errorCode":null,"errorMessage":"record updates should not reach code generation","messagePattern":"record updates should not reach code generation","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"compiler-core/src/javascript/expression.rs","lineNumber":2859,"sourceCode":"                | BinOp::SubInt\n                | BinOp::SubFloat\n                | BinOp::MultInt\n                | 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(","sourceCodeStart":2841,"sourceCodeEnd":2877,"githubUrl":"https://github.com/gleam-lang/gleam/blob/49f8762da595eb3c8f576656a4200a142ca188c9/compiler-core/src/javascript/expression.rs#L2841-L2877","documentation":"The JavaScript code generator does not implement `Constant::RecordUpdate`: record update syntax is not representable as a compile-time constant. This panic is a guard asserting such constants were eliminated or rejected in earlier compiler phases.","triggerScenarios":"A `Constant::RecordUpdate` node reaches `constant_expression` in the JavaScript backend — e.g. a record update expression `..thing` used where a constant is expected (module constant, bit array size, or similar) that earlier validation failed to reject.","commonSituations":"Writing a module-level constant that uses record-update syntax; compiler regression where constant lowering missed the RecordUpdate variant.","solutions":["Rewrite the constant to not use record-update syntax (construct the record fully inside the constant).","Move the record update out of constant position into a function body, where it is supported.","If this occurs with valid-looking code, report it as a Gleam compiler bug."],"exampleFix":"// before\npub const config = Config(..base, retries: 3)\n// after\npub const config = Config(host: base.host, retries: 3)","handlingStrategy":"validation","validationCode":"// reject record updates in constant position before codegen\nif let Constant::RecordUpdate { location, .. } = constant {\n    return Err(error_unsupported_in_constant(location));\n}","typeGuard":"fn is_codegen_constant(c: &Constant) -> bool {\n    !matches!(c, Constant::RecordUpdate { .. } | Constant::Todo { .. } | Constant::Invalid { .. })\n}","tryCatchPattern":"match std::panic::catch_unwind(|| codegen_constant(&c)) {\n    Ok(doc) => doc,\n    Err(_) => emit_internal_error_diagnostic(),\n}","preventionTips":["Never use record-update syntax in module constants; construct records fully.","Run `gleam check` so constant misuse is caught with a proper diagnostic.","When adding AST variants, update every backend's constant printer."],"tags":["compiler","panic","code-generation","record-update"],"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"}