risingwavelabs/risingwave · error

type inference function cannot be automatically derived. You

Error message

type inference function cannot be automatically derived. You should provide: `type_infer = "|args| Ok(...)"`

What it means

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.

Source

Thrown at src/expr/macro/src/gen.rs:123

                // infer as the array type of "any" argument
                return Ok(quote! { |args| Ok(DataType::list(args[#i].clone())) });
            }
        } else if self.ret == "struct" {
            if let Some(i) = self.args.iter().position(|t| t == "struct") {
                // infer as the type of "struct" argument
                return Ok(quote! { |args| Ok(args[#i].clone()) });
            }
        } else if self.ret == "anymap" {
            if let Some(i) = self.args.iter().position(|t| t == "anymap") {
                // infer as the type of "anymap" argument
                return Ok(quote! { |args| Ok(args[#i].clone()) });
            }
        } else {
            // the return type is fixed
            let ty = data_type(&self.ret);
            return Ok(quote! { |_| Ok(#ty) });
        }
        Err(Error::new(
            Span::call_site(),
            "type inference function cannot be automatically derived. You should provide: `type_infer = \"|args| Ok(...)\"`",
        ))
    }

    /// Generate a descriptor (`FuncSign`) of the scalar or table function.
    ///
    /// The types of arguments and return value should not contain wildcard.
    ///
    /// # Arguments
    /// `build_fn`: whether the user provided a function is a build function.
    /// (from the `#[build_function]` macro)
    pub fn generate_function_descriptor(
        &self,
        user_fn: &UserFunctionAttr,
        build_fn: bool,
    ) -> Result<TokenStream2> {
        if self.is_table_function {

View on GitHub (pinned to 6469eb736d)

Solutions

  1. Add `type_infer = "|args| Ok(...)"` to the function declaration
  2. Set `ret` to a concrete DataType if the return type is actually fixed
  3. Set `ret = "any"` if the function should return the same type as a typed argument

Example fix

// before
["array_position", ret = "@>"]
// after
["array_position", ret = "@>", type_infer = "|args| Ok(args[0].clone())"]
Defensive patterns

Strategy: validation

Validate before calling

// compile-time check is enough; also audit declarations:
grep -L 'type_infer' src/expr/**/function_registry.rs | xargs grep -n 'ret = "@'  # declarations with dependent ret but no type_infer

Prevention

When it happens

Trigger: 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"`.

Common situations: 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.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


AI-assisted analysis of risingwavelabs/risingwave@6469eb736d (2026-09-11). Data as JSON: /api/errors/473ba6079f0dac6b. Report an issue: GitHub.