{"record":{"id":"03513d888f69ab38","repo":"swc-project/swc","slug":"ast-node-enum-cannot-contain-named-fields-or-un","errorCode":null,"errorMessage":"#[ast_node] enum cannot contain named fields or unit variant","messagePattern":"#\\[ast_node\\] enum cannot contain named fields or unit variant","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/ast_node/src/enum_deserialize.rs","lineNumber":52,"sourceCode":"    let deserialize = {\n        let mut all_tags: Punctuated<_, token::Comma> = Default::default();\n        let tag_match_arms = data\n            .variants\n            .iter()\n            .filter(|v| !crate::encoding::is_unknown(&v.attrs))\n            .map(|variant| {\n                let field_type = match variant.fields {\n                    Fields::Unnamed(ref fields) => {\n                        assert_eq!(\n                            fields.unnamed.len(),\n                            1,\n                            \"#[ast_node] enum cannot contain variant with multiple fields\"\n                        );\n\n                        fields.unnamed.last().unwrap().ty.clone()\n                    }\n                    _ => {\n                        unreachable!(\"#[ast_node] enum cannot contain named fields or unit variant\")\n                    }\n                };\n                let tags = variant\n                    .attrs\n                    .iter()\n                    .filter_map(|attr| -> Option<VariantAttr> {\n                        if !is_attr_name(attr, \"tag\") {\n                            return None;\n                        }\n                        let tokens = match &attr.meta {\n                            Meta::List(meta) => meta.tokens.clone(),\n                            _ => {\n                                panic!(\"#[tag] attribute must be in form of #[tag(..)]\")\n                            }\n                        };\n                        let tags = parse2(tokens).expect(\"failed to parse #[tag] attribute\");\n\n                        Some(tags)","sourceCodeStart":34,"sourceCodeEnd":70,"githubUrl":"https://github.com/swc-project/swc/blob/5176682b65416c6b5de6b47379ae1588ea3ecb3f/crates/ast_node/src/enum_deserialize.rs#L34-L70","documentation":"A derive-macro validation panic in the #[ast_node] deserializer expansion (enum_deserialize.rs:52). While generating tag-match arms for the enum's variants, the macro asserts each variant is a single unnamed field (a newtype variant); this panic fires for a variant that has named fields or is a unit variant, shapes the internally-tagged deserialization code generator cannot handle. The offending enum definition in the user's source is the input at fault.","triggerScenarios":"Thrown at crates/ast_node/src/enum_deserialize.rs:52 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Refactor the #[ast_node] enum so every variant is a newtype variant with exactly one field","Split data-carrying payloads into separate structs wrapped by newtype variants","Emit a spanned compile_error! naming the offending variant instead of a bare 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-14T05:17:10.506Z"}