{"record":{"id":"e46ffb66d8da00c6","repo":"denoland/deno","slug":"unions-are-not-supported-e46ffb","errorCode":null,"errorMessage":"Unions are not supported","messagePattern":"Unions are not supported","errorType":"validation","errorClass":"syn::Error","httpStatus":null,"severity":"error","filePath":"libs/ops/conversion/to_v8/mod.rs","lineNumber":41,"sourceCode":"\n  let out = match input.data {\n    Data::Struct(data) => {\n      let fields = destruct_fields(&data.fields)?;\n      let body = r#struct::get_body(span, data)?;\n\n      create_impl(\n        ident,\n        &generics,\n        quote! {\n          let Self #fields = self;\n          #body\n        },\n      )\n    }\n    Data::Enum(data) => {\n      create_impl(ident, &generics, r#enum::get_body(span, input.attrs, data)?)\n    }\n    Data::Union(_) => return Err(Error::new(span, \"Unions are not supported\")),\n  };\n\n  Ok(out)\n}\n\nfn destruct_fields(fields: &Fields) -> Result<TokenStream, Error> {\n  match fields {\n    Fields::Named { 0: named } => {\n      let fields = named\n        .named\n        .iter()\n        .map(|field| field.ident.as_ref().unwrap());\n\n      Ok(quote! {\n        {\n          #(#fields),*\n        }\n      })","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/denoland/deno/blob/9ad36f7a2cce60488e6ec52283efb32efddaf93a/libs/ops/conversion/to_v8/mod.rs#L23-L59","documentation":"#[derive(ToV8)] routes Data::Struct and Data::Enum inputs to generated ToV8 impls, but Data::Union is rejected with this error on the item's span. A union's active-field semantics cannot be represented when converting to a V8 value, so the derive fails fast rather than guessing a layout.","triggerScenarios":"Annotating a union with #[derive(ToV8)], e.g. #[derive(ToV8)] union Raw { a: u32, b: f32 } returned or accepted by an op.","commonSituations":"Shared derive preludes applied to every type in a module including FFI unions; refactoring a struct into a union while keeping its derives.","solutions":["Model the 'one of several layouts' as an enum with a variant per alternative, which serializes naturally to V8.","Keep unions behind manual conversion: write an op that reads the union and returns a normal struct/array to JS."],"exampleFix":"// before\n#[derive(ToV8)]\nunion Raw {\n  a: u32,\n  b: f32,\n} // error: Unions are not supported\n\n// after\n#[derive(ToV8)]\nenum Raw {\n  A(u32),\n  B(f32),\n}","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Unions cannot be exposed to JS via conversion derives — convert them to enums or wrap them behind a hand-written op.","Review any blanket derive lists in preludes when FFI unions live in the same module."],"tags":["proc-macro","derive","to-v8","union","compile-time","deno-core"],"backgroundTag":"derive-macro-unsupported-shape","analyzedSha":"9ad36f7a2cce60488e6ec52283efb32efddaf93a","analyzedAt":"2026-08-20T13:07:44.778Z","contentChangedAt":"2026-08-20T13:07:44.778Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}