{"record":{"id":"7485127efb4eed85","repo":"swc-project/swc","slug":"generic-parameter-other-than-type","errorCode":null,"errorMessage":"generic parameter other than type","messagePattern":"generic parameter other than type","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/swc_ecma_quote_macros/src/ret_type.rs","lineNumber":91,"sourceCode":"    let mut parser = Parser::new_from(lexer);\n    op(&mut parser)\n        .map_err(|err| anyhow!(\"{err:?}\"))\n        .with_context(|| format!(\"failed to parse input as `{}`\", type_name::<T>()))\n        .map(|val| BoxWrapper(Box::new(val)))\n}\n\nfn extract_generic<'a>(name: &str, ty: &'a Type) -> Option<&'a Type> {\n    if let Type::Path(p) = ty {\n        let last = p.path.segments.last().unwrap();\n\n        if !last.arguments.is_empty() && last.ident == name {\n            match &last.arguments {\n                PathArguments::AngleBracketed(tps) => {\n                    let arg = tps.args.first().unwrap();\n\n                    match arg {\n                        GenericArgument::Type(arg) => return Some(arg),\n                        _ => unimplemented!(\"generic parameter other than type\"),\n                    }\n                }\n                _ => unimplemented!(\"Box() -> T or Box without a type parameter\"),\n            }\n        }\n    }\n\n    None\n}\n","sourceCodeStart":73,"sourceCodeEnd":101,"githubUrl":"https://github.com/swc-project/swc/blob/d7d74346665e36e692aa07e13d4ee3ee692ee35c/crates/swc_ecma_quote_macros/src/ret_type.rs#L73-L101","documentation":"`quote!` from swc_ecma_quote_macros reads the type written after `as` (e.g. `quote!(\"a + b\" as Box<Expr>)`) to decide how to parse and wrap the fragment. `extract_generic` only accepts an angle-bracketed argument list whose first argument is a plain type; any other generic-argument kind (lifetime or const argument) hits `unimplemented!(\"generic parameter other than type\")` at compile time.","triggerScenarios":"Write a quote invocation whose wrapper type's first generic argument is not a type — e.g. `Box<'a>` or a const-generic parameter — instead of the supported `Box<T>` / `Option<T>` shapes.","commonSituations":"Writing custom visitor or matcher macros on top of swc's quote macros; refactors that move lifetimes into the wrapper position; meta-macros generating quote calls with spliced tokens.","solutions":["Use the supported forms: `as Box<Expr>` or `as Option<Expr>` with a plain type argument","Wrap a parameterized inner type in a type alias so the outer argument stays a plain type"],"exampleFix":"// before\nlet node = quote!(\"self.field\" as Box<'a>);\n\n// after\nlet node = quote!(\"self.field\" as Box<Expr>);","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Restrict quote! `as` types to `Box<T>` / `Option<T>` with a single plain type argument","If another macro generates quote! calls, snapshot-test the emitted tokens with cargo-expand"],"tags":["macro","quote","compile-time","generics"],"backgroundTag":null,"analyzedSha":"d7d74346665e36e692aa07e13d4ee3ee692ee35c","analyzedAt":"2026-08-16T12:41:13.160Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}