denoland/deno · error · syn::Error

Unnamed fields are currently not supported

Error message

Unnamed fields are currently not supported

What it means

The `#[webidl(dictionary)]` converter generator (libs/ops/webidl/dictionary.rs) only handles structs with named fields, because a WebIDL dictionary is by definition a set of named members. `get_body` matches on `DataStruct::fields` and rejects tuple structs with this error on the struct's span.

Source

Thrown at libs/ops/webidl/dictionary.rs:33

use syn::Token;
use syn::Type;
use syn::ext::IdentExt;
use syn::parse::Parse;
use syn::parse::ParseStream;
use syn::punctuated::Punctuated;
use syn::spanned::Spanned;

use super::kw;

pub fn get_body(
  ident_string: String,
  span: Span,
  data: DataStruct,
) -> Result<TokenStream, Error> {
  let fields = match data.fields {
    Fields::Named(fields) => fields,
    Fields::Unnamed(_) => {
      return Err(Error::new(
        span,
        "Unnamed fields are currently not supported",
      ));
    }
    Fields::Unit => {
      return Err(Error::new(span, "Unit fields are currently not supported"));
    }
  };

  let mut fields = fields
    .named
    .into_iter()
    .map(TryInto::try_into)
    .collect::<Result<Vec<DictionaryField>, Error>>()?;
  fields.sort_by(|a, b| a.name.cmp(&b.name));

  let names = fields
    .iter()

View on GitHub (pinned to 9ad36f7a2c)

Solutions

  1. Convert the struct to named fields: `struct Point { x: f64, y: f64 }` — each field becomes a dictionary member with a camelCased JS name.
  2. For newtype wrappers, implement the conversion manually or map the inner value to a named field.

Example fix

// before
#[derive(WebIDL)]
#[webidl(dictionary)]
struct Point(f64, f64);

// after
#[derive(WebIDL)]
#[webidl(dictionary)]
struct Point { pub x: f64, pub y: f64 }
Defensive patterns

Strategy: validation

Validate before calling

// Compile-time: `cargo check`. Rule of thumb: webidl dictionary == struct with
// named fields only. Reject tuple structs before adding the derive.

Prevention

When it happens

Trigger: `#[derive(WebIDL)] #[webidl(dictionary)] struct Point(String, f64);` — any tuple struct passed to the webidl dictionary derive.

Common situations: Reusing an existing tuple struct (a newtype wrapper like `struct Handle(u32)`) as a webidl dictionary; refactoring named fields into positional ones.

Related errors


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