{"record":{"id":"63c10c3e3390c363","repo":"swc-project/swc","slug":"unknown-member-must-be-a-tag-and-a-value-63c10c","errorCode":null,"errorMessage":"unknown member must be a tag and a value","messagePattern":"unknown member must be a tag and a value","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/ast_node/src/encoding/encode.rs","lineNumber":109,"sourceCode":"                    );\n\n                    match &unknown.fields {\n                        syn::Fields::Unnamed(fields) => match fields.unnamed.len() {\n                            1 => {\n                                assert_eq!(enum_type, EnumType::Unit);\n                                syn::parse_quote! {\n                                    #ident::#name(tag)\n                                        => tag.encode(writer)?,\n                                }\n                            }\n                            2 => {\n                                assert_eq!(enum_type, EnumType::One);\n                                syn::parse_quote! {\n                                    #ident::#name(tag, value)\n                                        => cbor4ii::core::types::Tag((*tag).into(), &*value).encode(writer)?,\n                                }\n                            }\n                            _ => panic!(\"unknown member must be a tag and a value\"),\n                        },\n                        _ => panic!(\"named enum unsupported\"),\n                    }\n                });\n\n            if matches!(enum_type, EnumType::Struct) {\n                assert!(\n                    unknown_arm.is_none(),\n                    \"struct enum does not allow unknown variants\"\n                );\n            }\n\n            let mut discriminant: u32 = 0;\n            let fields = iter.map(|field| -> syn::Arm {\n                match field.discriminant.as_ref() {\n                    Some((_, syn::Expr::Lit(syn::ExprLit { lit: syn::Lit::Int(lit), .. }))) => {\n                        discriminant = lit.base10_parse::<u32>().unwrap();\n                    },","sourceCodeStart":91,"sourceCodeEnd":127,"githubUrl":"https://github.com/swc-project/swc/blob/5176682b65416c6b5de6b47379ae1588ea3ecb3f/crates/ast_node/src/encoding/encode.rs#L91-L127","documentation":"The #[encoding(unknown)] variant is how the generated encoder round-trips unknown CBOR tags. The macro's match on its field count only handles 1 (encode the bare tag) and 2 (encode cbor4ii Tag(tag, value)); any other arity has no meaning, so expansion panics with 'unknown member must be a tag and a value'. #[ast_node] generates the correct shape automatically; this fires for hand-written Encode derives.","triggerScenarios":"Hand-writing derive(Encode) (not via #[ast_node]) on an enum with a #[encoding(unknown)] variant of arity 0 or 3+ unnamed fields.","commonSituations":"Custom AST nodes targeting swc_ast_unknown builds; manually porting the generated Unknown variant with the wrong shape.","solutions":["Declare it as exactly `#[encoding(unknown)] Unknown(u32)` or `#[encoding(unknown)] Unknown(u32, YourUnknownType)`.","Prefer #[ast_node(...)] so the Unknown variant is generated correctly.","Keep the unknown variant first — the macro also asserts it precedes tagged variants."],"exampleFix":"// before\n#[derive(Encode, Decode)]\nenum Expr {\n    #[encoding(unknown)]\n    Unknown(u32, u32, u32),\n    Num { value: f64 },\n}\n\n// after — tag + value tuple\n#[derive(Encode, Decode)]\nenum Expr {\n    #[encoding(unknown)]\n    Unknown(u32, swc_common::unknown::Unknown),\n    Num { value: f64 },\n}","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Prefer #[ast_node(...)] over manual Encode/Decode derives so the Unknown variant is generated correctly.","If hand-writing, use exactly Unknown(u32) or Unknown(u32, swc_common::unknown::Unknown).","Keep the #[encoding(unknown)] variant first in the enum."],"tags":["rust","proc-macro","derive","encode","enum","unknown-variant"],"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-14T05:17:10.506Z"}