{"record":{"id":"edca1179f17cdfc7","repo":"gleam-lang/gleam","slug":"record-updates-should-not-reach-code-generation","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/erlang.rs","lineNumber":4396,"sourceCode":"    let mut overridden_publicity = imbl::HashSet::new();\n\n    for constant in &module.definitions.constants {\n        if constant.publicity.is_importable() {\n            find_referenced_private_functions(&constant.value, &mut overridden_publicity);\n        }\n    }\n    overridden_publicity\n}\n\nfn find_referenced_private_functions(\n    constant: &TypedConstant,\n    already_found: &mut imbl::HashSet<EcoString>,\n) {\n    match constant {\n        Constant::Todo { .. } => panic!(\"todo constants should not reach code generation\"),\n        Constant::Invalid { .. } => panic!(\"invalid constants should not reach code generation\"),\n        Constant::RecordUpdate { .. } => {\n            panic!(\"record updates should not reach code generation\")\n        }\n\n        Constant::Int { .. }\n        | Constant::Float { .. }\n        | Constant::String { .. }\n        | Constant::BitArray { .. } => (),\n\n        TypedConstant::Var {\n            name, constructor, ..\n        } => {\n            if let Some(ValueConstructor { type_, .. }) = constructor.as_deref()\n                && let Type::Fn { .. } = **type_\n            {\n                let _ = already_found.insert(name.clone());\n            }\n        }\n\n        TypedConstant::Record { arguments, .. } => arguments","sourceCodeStart":4378,"sourceCodeEnd":4414,"githubUrl":"https://github.com/gleam-lang/gleam/blob/15b07c783065c92bb016b1b74ed0995a5259850f/compiler-core/src/erlang.rs#L4378-L4414","documentation":"An internal compiler assertion: a Constant::RecordUpdate node reached find_referenced_private_functions during Erlang code generation. Record-update constants should be rejected or desugared by earlier compiler phases (parsing/type checking), so their presence in codegen means an invariant was broken.","triggerScenarios":"A record update expression used in a constant position (e.g. inside a pub const) survives to the erlang.rs code generator instead of being rejected earlier.","commonSituations":"Writing something like `pub const cfg = ..{ ..cfg, flag: True }` in a context where constant record updates are not supported; a compiler bug letting the construct slip through validation.","solutions":["Rewrite the constant without a record-update expression (construct the record fully and explicitly).","Update gleam to the latest version; unsupported-constant handling may have been fixed.","File a minimal reproducing example as a bug at github.com/gleam-lang/gleam."],"exampleFix":"// before\npub const cfg = Config(..base_config, flag: True)\n// after\npub const cfg = Config(field1: base_config.field1, flag: True)","handlingStrategy":"validation","validationCode":"// Avoid record updates in constant positions before building\n// grep for 'const' declarations containing '..' record-update syntax\ngrep -nE 'const\\s+\\w+\\s*=.*\\.\\.' src/","typeGuard":"match constant { Constant::RecordUpdate { .. } => None, c => Some(c) }","tryCatchPattern":"let status = Command::new(\"gleam\").args([\"build\"]).status()?;\nif !status.success() { /* inspect compiler output */ }","preventionTips":["Do not use `..record` update syntax inside `pub const` declarations.","Construct constants fully and explicitly instead of updating a base record.","Keep gleam updated so unsupported constant forms get proper diagnostics."],"tags":["compiler","internal","codegen","assertion"],"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"}