denoland/deno · error · syn::Error

Enums currently do not support dictionary converters

Error message

Enums currently do not support dictionary converters

What it means

The mirror case: `webidl(dictionary)` generators only handle structs. An `enum` carrying `#[webidl(dictionary)]` is rejected in libs/ops/webidl/mod.rs with this error on the enum's span, because dictionaries need named struct members to map to WebIDL members.

Source

Thrown at libs/ops/webidl/mod.rs:43

    .attrs
    .into_iter()
    .find_map(|attr| ConverterType::from_attribute(attr).transpose())
    .ok_or_else(|| {
      Error::new(span, "missing top-level #[webidl] attribute")
    })??;

  let out = match input.data {
    Data::Struct(data) => match converter {
      ConverterType::Dictionary => {
        create_impl(ident, dictionary::get_body(ident_string, span, data)?)
      }
      ConverterType::Enum => {
        return Err(Error::new(span, "Structs do not support enum converters"));
      }
    },
    Data::Enum(data) => match converter {
      ConverterType::Dictionary => {
        return Err(Error::new(
          span,
          "Enums currently do not support dictionary converters",
        ));
      }
      ConverterType::Enum => {
        let (body, as_str) = r#enum::get_body(ident_string, &ident, data)?;
        let implementation = create_impl(ident, body);

        quote! {
          #implementation
          #as_str
        }
      }
    },
    Data::Union(_) => return Err(Error::new(span, "Unions are not supported")),
  };

  Ok(out)

View on GitHub (pinned to 9ad36f7a2c)

Solutions

  1. For enums, use `#[webidl(enum)]` (with unit variants only).
  2. If dictionary semantics are required, convert the item into a struct with named fields.

Example fix

// before
#[derive(WebIDL)]
#[webidl(dictionary)]
enum Color { Red, Green }

// after
#[derive(WebIDL)]
#[webidl(enum)]
enum Color { Red, Green }
Defensive patterns

Strategy: validation

Validate before calling

// Compile-time: `cargo check`. Pairing rule (mirror of 2016):
//   enum    -> #[webidl(enum)]
//   struct  -> #[webidl(dictionary)]

Prevention

When it happens

Trigger: `#[webidl(dictionary)] enum Color { Red, Green }` — annotating an enum with the dictionary converter.

Common situations: Turning a struct into an enum (or generalizing a type) without updating the webidl attribute; copy-paste from a dictionary struct.

Related errors


AI-assisted analysis of denoland/deno@9ad36f7a2c (2026-08-20). Data as JSON: /api/errors/530588b83f059d1b. Report an issue: GitHub.