denoland/deno · error · syn::Error

duplicate `default` argument

Error message

duplicate `default` argument

What it means

When parsing `webidl(...)` arguments on an op parameter, `WebIDLArgs::parse` (libs/ops/op2/signature.rs) allows at most one `default = <expr>` entry. The parser stores the first `default` and raises this error on the span of the second `default` key it encounters.

Source

Thrown at libs/ops/op2/signature.rs:301

impl Eq for WebIDLDefault {}

#[derive(Clone, Debug, Eq, PartialEq)]
pub struct WebIDLArgs {
  pub default: Option<WebIDLDefault>,
  pub options: Vec<WebIDLPair>,
}

impl Parse for WebIDLArgs {
  fn parse(input: ParseStream) -> syn::Result<Self> {
    let mut default: Option<WebIDLDefault> = None;
    let mut options: Vec<WebIDLPair> = Vec::new();

    while !input.is_empty() {
      let key: Ident = input.parse()?;

      if key == "default" {
        if default.is_some() {
          return Err(syn::Error::new(
            key.span(),
            "duplicate `default` argument",
          ));
        }
        input.parse::<Token![=]>()?;
        default = Some(WebIDLDefault(input.parse::<syn::Expr>()?));
      } else if key == "options" {
        if !options.is_empty() {
          return Err(syn::Error::new(
            key.span(),
            "duplicate `options` argument",
          ));
        }
        let content;
        syn::parenthesized!(content in input);
        let parsed_options =
          content.parse_terminated(WebIDLPair::parse, Token![,])?;
        options = parsed_options.into_iter().collect();

View on GitHub (pinned to 9ad36f7a2c)

Solutions

  1. Keep exactly one `default = <expr>` entry per webidl attribute and delete the duplicate.
  2. If you need a compound fallback, encode it in the single expression, e.g. `default = cfg().unwrap_or(DEFAULT)`.
  3. Split genuinely different behavior into two ops or two parameters instead of two defaults.

Example fix

// before
#[op2(webidl(default = Color::Red, default = Color::Blue))]
color: Color,

// after
#[op2(webidl(default = Color::Red))]
color: Color,
Defensive patterns

Strategy: validation

Validate before calling

// Compile-time: `cargo check`. If generating op2 signatures programmatically,
// emit at most one `default = ...` per webidl(...) group.

Prevention

When it happens

Trigger: `#[op2(webidl(default = A, default = B))]` on a parameter — two `default` keys in a single webidl attribute; also `default` repeated after `options(...)` entries in the same list.

Common situations: Adding a second default while tweaking fallback behavior and forgetting the first; merging two branches that each added a default.

Related errors


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