{"record":{"id":"e08223e7eb5d096c","repo":"swc-project/swc","slug":"derive-merge-does-not-support-a-union","errorCode":null,"errorMessage":"derive(Merge) does not support a union","messagePattern":"derive\\(Merge\\) does not support a union","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/swc_config_macro/src/merge.rs","lineNumber":23,"sourceCode":"\npub fn expand(input: DeriveInput) -> TokenStream {\n    match &input.data {\n        syn::Data::Struct(s) => {\n            let body = call_merge_for_fields(&quote!(self), &s.fields);\n            let body = join_stmts(&body);\n\n            let ident = &input.ident;\n            parse_quote!(\n                #[automatically_derived]\n                impl swc_config::merge::Merge for #ident {\n                    fn merge(&mut self, _other: Self) {\n                        #body\n                    }\n                }\n            )\n        }\n        syn::Data::Enum(_) => unimplemented!(\"derive(Merge) does not support an enum\"),\n        syn::Data::Union(_) => unimplemented!(\"derive(Merge) does not support a union\"),\n    }\n}\n\nfn call_merge_for_fields(obj: &dyn ToTokens, fields: &Fields) -> Vec<Stmt> {\n    fn call_merge(obj: &dyn ToTokens, idx: usize, f: &Field) -> Expr {\n        let r = quote!(_other);\n\n        let l = access_field(obj, idx, f);\n        let r = access_field(&r, idx, f);\n        parse_quote!(swc_config::merge::Merge::merge(&mut #l, #r))\n    }\n\n    match fields {\n        Fields::Named(fs) => fs\n            .named\n            .iter()\n            .enumerate()\n            .map(|(idx, f)| call_merge(obj, idx, f))","sourceCodeStart":5,"sourceCodeEnd":41,"githubUrl":"https://github.com/swc-project/swc/blob/5176682b65416c6b5de6b47379ae1588ea3ecb3f/crates/swc_config_macro/src/merge.rs#L5-L41","documentation":"A derive-macro validation abort in expand of swc_config_macro's Merge derive (merge.rs:23). Mirroring the enum case, when the annotated DeriveInput is a union there is no meaningful field-wise merge to generate, so the macro expansion panics with 'derive(Merge) does not support a union'. The union type annotated with #[derive(Merge)] is the input at fault.","triggerScenarios":"Thrown at crates/swc_config_macro/src/merge.rs:23 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Convert the union to a struct if config merging is needed","Write a manual Merge impl if union-specific semantics are desired","Produce a spanned compile_error! identifying the union instead of a panic"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"5176682b65416c6b5de6b47379ae1588ea3ecb3f","analyzedAt":"2026-08-17T16:16:52.067Z","contentChangedAt":"2026-08-17T16:16:52.067Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}