{"record":{"id":"473ba6079f0dac6b","repo":"risingwavelabs/risingwave","slug":"type-inference-function-cannot-be-automatically-de","errorCode":null,"errorMessage":"type inference function cannot be automatically derived. You should provide: `type_infer = \"|args| Ok(...)\"`","messagePattern":"type inference function cannot be automatically derived\\. You should provide: `type_infer = \"\\|args\\| Ok\\(\\.\\.\\.\\)\"`","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/expr/macro/src/gen.rs","lineNumber":123,"sourceCode":"                // infer as the array type of \"any\" argument\n                return Ok(quote! { |args| Ok(DataType::list(args[#i].clone())) });\n            }\n        } else if self.ret == \"struct\" {\n            if let Some(i) = self.args.iter().position(|t| t == \"struct\") {\n                // infer as the type of \"struct\" argument\n                return Ok(quote! { |args| Ok(args[#i].clone()) });\n            }\n        } else if self.ret == \"anymap\" {\n            if let Some(i) = self.args.iter().position(|t| t == \"anymap\") {\n                // infer as the type of \"anymap\" argument\n                return Ok(quote! { |args| Ok(args[#i].clone()) });\n            }\n        } else {\n            // the return type is fixed\n            let ty = data_type(&self.ret);\n            return Ok(quote! { |_| Ok(#ty) });\n        }\n        Err(Error::new(\n            Span::call_site(),\n            \"type inference function cannot be automatically derived. You should provide: `type_infer = \\\"|args| Ok(...)\\\"`\",\n        ))\n    }\n\n    /// Generate a descriptor (`FuncSign`) of the scalar or table function.\n    ///\n    /// The types of arguments and return value should not contain wildcard.\n    ///\n    /// # Arguments\n    /// `build_fn`: whether the user provided a function is a build function.\n    /// (from the `#[build_function]` macro)\n    pub fn generate_function_descriptor(\n        &self,\n        user_fn: &UserFunctionAttr,\n        build_fn: bool,\n    ) -> Result<TokenStream2> {\n        if self.is_table_function {","sourceCodeStart":105,"sourceCodeEnd":141,"githubUrl":"https://github.com/risingwavelabs/risingwave/blob/6469eb736d691e8e9b8a419a57edd6429ca77417/src/expr/macro/src/gen.rs#L105-L141","documentation":"When a function declaration has no explicit `type_infer` and its return type is not a fixed type or `any`, the macro cannot derive a `fn(&[DataType]) -> Result<DataType>` automatically and fails at compile time, telling the author to supply a type_infer closure.","triggerScenarios":"Declaring a function in define_function! without `type_infer` while its `ret` is a generic/dependent type (not a concrete DataType and not `any`), e.g. `ret = \"Array\"`.","commonSituations":"Writing a new UDF whose return type depends on the input (arrays, structs, dynamic casts) and omitting type_infer; copy-pasting a declaration and removing the fixed return type.","solutions":["Add `type_infer = \"|args| Ok(...)\"` to the function declaration","Set `ret` to a concrete DataType if the return type is actually fixed","Set `ret = \"any\"` if the function should return the same type as a typed argument"],"exampleFix":"// before\n[\"array_position\", ret = \"@>\"]\n// after\n[\"array_position\", ret = \"@>\", type_infer = \"|args| Ok(args[0].clone())\"]","handlingStrategy":"validation","validationCode":"// compile-time check is enough; also audit declarations:\ngrep -L 'type_infer' src/expr/**/function_registry.rs | xargs grep -n 'ret = \"@'  # declarations with dependent ret but no type_infer","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always provide type_infer when ret is not a concrete DataType","Add a macro-time check that dependent return types require type_infer","Copy existing declarations of the same category as templates"],"tags":["macro","type-inference","proc-macro","compile-time"],"backgroundTag":"missing-required-argument","analyzedSha":"6469eb736d691e8e9b8a419a57edd6429ca77417","analyzedAt":"2026-09-11T21:06:21.487Z","contentChangedAt":"2026-09-11T21:06:21.487Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}