{"record":{"id":"52229926a63dd160","repo":"denoland/deno","slug":"duplicate-default-argument","errorCode":null,"errorMessage":"duplicate `default` argument","messagePattern":"duplicate `default` argument","errorType":"validation","errorClass":"syn::Error","httpStatus":null,"severity":"error","filePath":"libs/ops/op2/signature.rs","lineNumber":301,"sourceCode":"impl Eq for WebIDLDefault {}\n\n#[derive(Clone, Debug, Eq, PartialEq)]\npub struct WebIDLArgs {\n  pub default: Option<WebIDLDefault>,\n  pub options: Vec<WebIDLPair>,\n}\n\nimpl Parse for WebIDLArgs {\n  fn parse(input: ParseStream) -> syn::Result<Self> {\n    let mut default: Option<WebIDLDefault> = None;\n    let mut options: Vec<WebIDLPair> = Vec::new();\n\n    while !input.is_empty() {\n      let key: Ident = input.parse()?;\n\n      if key == \"default\" {\n        if default.is_some() {\n          return Err(syn::Error::new(\n            key.span(),\n            \"duplicate `default` argument\",\n          ));\n        }\n        input.parse::<Token![=]>()?;\n        default = Some(WebIDLDefault(input.parse::<syn::Expr>()?));\n      } else if key == \"options\" {\n        if !options.is_empty() {\n          return Err(syn::Error::new(\n            key.span(),\n            \"duplicate `options` argument\",\n          ));\n        }\n        let content;\n        syn::parenthesized!(content in input);\n        let parsed_options =\n          content.parse_terminated(WebIDLPair::parse, Token![,])?;\n        options = parsed_options.into_iter().collect();","sourceCodeStart":283,"sourceCodeEnd":319,"githubUrl":"https://github.com/denoland/deno/blob/9ad36f7a2cce60488e6ec52283efb32efddaf93a/libs/ops/op2/signature.rs#L283-L319","documentation":"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.","triggerScenarios":"`#[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.","commonSituations":"Adding a second default while tweaking fallback behavior and forgetting the first; merging two branches that each added a default.","solutions":["Keep exactly one `default = <expr>` entry per webidl attribute and delete the duplicate.","If you need a compound fallback, encode it in the single expression, e.g. `default = cfg().unwrap_or(DEFAULT)`.","Split genuinely different behavior into two ops or two parameters instead of two defaults."],"exampleFix":"// before\n#[op2(webidl(default = Color::Red, default = Color::Blue))]\ncolor: Color,\n\n// after\n#[op2(webidl(default = Color::Red))]\ncolor: Color,","handlingStrategy":"validation","validationCode":"// Compile-time: `cargo check`. If generating op2 signatures programmatically,\n// emit at most one `default = ...` per webidl(...) group.","typeGuard":null,"tryCatchPattern":null,"preventionTips":["One `default` per webidl attribute; encode compound fallbacks inside the single expression.","Review diffs for duplicated `default =` keys in webidl attributes."],"tags":["op2","webidl","proc-macro","duplicate-argument","compile-time"],"backgroundTag":"duplicate-macro-argument","analyzedSha":"9ad36f7a2cce60488e6ec52283efb32efddaf93a","analyzedAt":"2026-08-20T13:07:44.778Z","contentChangedAt":"2026-08-20T13:07:44.778Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}