{"record":{"id":"389231927254a41c","repo":"swc-project/swc","slug":"more-than-1-unnamed-member-field-are-not-allowed-389231","errorCode":null,"errorMessage":"more than 1 unnamed member field are not allowed","messagePattern":"more than 1 unnamed member field are not allowed","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/ast_node/src/encoding/encode.rs","lineNumber":62,"sourceCode":"                        -> Result<(), cbor4ii::core::error::EncodeError<W::Error>>\n                    {\n                        #head\n                        #(#fields)*;\n                        Ok(())\n                    }\n                }\n            }\n        }\n        Data::Enum(data) => {\n            let enum_type = data.variants.iter().filter(|v| !is_unknown(&v.attrs)).fold(\n                None,\n                |mut sum, next| {\n                    let ty = match &next.fields {\n                        syn::Fields::Named(_) => EnumType::Struct,\n                        syn::Fields::Unnamed(fields) if fields.unnamed.len() == 1 => EnumType::One,\n                        syn::Fields::Unit => EnumType::Unit,\n                        syn::Fields::Unnamed(_) => {\n                            panic!(\"more than 1 unnamed member field are not allowed\")\n                        }\n                    };\n                    match (*sum.get_or_insert(ty), ty) {\n                        (EnumType::Struct, EnumType::Struct)\n                        | (EnumType::Struct, EnumType::Unit)\n                        | (EnumType::Unit, EnumType::Unit)\n                        | (EnumType::One, EnumType::One) => (),\n                        (EnumType::Unit, EnumType::One)\n                        | (EnumType::One, EnumType::Unit)\n                        | (_, EnumType::Struct) => sum = Some(EnumType::Struct),\n                        _ => panic!(\"enum member types must be consistent: {:?}\", (sum, ty)),\n                    }\n                    sum\n                },\n            );\n            let enum_type = enum_type.expect(\"enum cannot be empty\");\n            let mut iter = data.variants.iter().peekable();\n","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/swc-project/swc/blob/5176682b65416c6b5de6b47379ae1588ea3ecb3f/crates/ast_node/src/encoding/encode.rs#L44-L80","documentation":"The Encode derive (swc_common::Encode from the ast_node crate) classifies every non-#[encoding(unknown)] enum variant by shape: named fields map to Struct, exactly one unnamed field to One, no fields to Unit. A tuple variant with two or more fields has no representation in the generated CBOR tag encoding, so macro expansion panics with 'more than 1 unnamed member field are not allowed'. This is a compile-time constraint on the type definition, not a runtime encoding failure.","triggerScenarios":"Deriving Encode (or #[ast_node] with the encoding-impl feature) on an enum that contains a non-unknown variant with 2+ positional fields, such as `Pair(u32, u32)`.","commonSituations":"Porting serde-friendly enums into swc AST node types; adding a quick variant without reshaping it into a supported form.","solutions":["Reshape the variant into a named struct variant: `Pair { lo: u32, hi: u32 }`.","Or wrap the payloads in a single struct/newtype: `Pair(RangeFields)`.","Leave two-field tuples to the dedicated #[encoding(unknown)] tag+value variant, the only 2-field tuple allowed."],"exampleFix":"// before\n#[derive(Encode, Decode)]\nenum Bound {\n    Pair(u32, u32), // tuple with 2 fields\n}\n\n// after — named struct variant\n#[derive(Encode, Decode)]\nenum Bound {\n    Pair { lo: u32, hi: u32 },\n}","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Model multi-value enum payloads as named struct variants before deriving swc CBOR codecs.","cargo check the defining crate right after adding a variant to catch shape violations at authoring time.","Remember the only allowed tuple shapes: single-field newtype variants, and the 2-field #[encoding(unknown)] variant."],"tags":["rust","proc-macro","derive","encode","enum","cbor"],"backgroundTag":"derive-macro-enum-shape-invalid","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"}