slint-ui/slint · error

invalid number of argument for callback {}::{}

Error message

invalid number of argument for callback {}::{}

What it means

Error "invalid number of argument for callback {}::{}" thrown in slint-ui/slint.

Source

Thrown at internal/compiler/generator/rust_live_preview.rs:120

                callback.args.iter().map(|a| rust_primitive_type(a).unwrap()).collect::<Vec<_>>();
            let return_type = rust_primitive_type(&callback.return_type).unwrap();
            let args_name =
                (0..callback.args.len()).map(|i| format_ident!("arg_{}", i)).collect::<Vec<_>>();
            let caller_ident = accessor_names::rust_accessor_ident(name, AccessorKind::Invoker);
            property_and_callback_accessors.push(quote!(
                #[allow(dead_code)]
                pub fn #caller_ident(&self, #(#args_name : #callback_args,)*) -> #return_type {
                    self.0.borrow().invoke(#prop_name, &[#(#args_name.into(),)*])
                        .try_into().unwrap_or_else(|_| panic!("Invalid return type for callback {}::{}", #component_name, #prop_name))
                }
            ));
            let on_ident = accessor_names::rust_accessor_ident(name, AccessorKind::Handler);
            property_and_callback_accessors.push(quote!(
                #[allow(dead_code)]
                pub fn #on_ident(&self, f: impl FnMut(#(#callback_args),*) -> #return_type + 'static) {
                    let f = ::core::cell::RefCell::new(f);
                    self.0.borrow().set_callback(#prop_name, sp::Rc::new(move |values| {
                        let [#(#args_name,)*] = values else { panic!("invalid number of argument for callback {}::{}", #component_name, #prop_name) };
                        (*f.borrow_mut())(#(#args_name.clone().try_into().unwrap_or_else(|_| panic!("invalid argument for callback {}::{}", #component_name, #prop_name)),)*).into()
                    }))
                }
            ));
        } else if let Type::Function(function) = &p.ty {
            let callback_args =
                function.args.iter().map(|a| rust_primitive_type(a).unwrap()).collect::<Vec<_>>();
            let return_type = rust_primitive_type(&function.return_type).unwrap();
            let args_name =
                (0..function.args.len()).map(|i| format_ident!("arg_{}", i)).collect::<Vec<_>>();
            let caller_ident = accessor_names::rust_accessor_ident(name, AccessorKind::Invoker);
            property_and_callback_accessors.push(quote!(
                #[allow(dead_code)]
                pub fn #caller_ident(&self, #(#args_name : #callback_args,)*) -> #return_type {
                    self.0.borrow().invoke(#prop_name, &[#(#args_name.into(),)*])
                        .try_into().unwrap_or_else(|_| panic!("Invalid return type for function {}::{}", #component_name, #prop_name))
                }
            ));

View on GitHub (pinned to 3fd8f2ec03)

Solutions

  1. Match the number of arguments in the Rust callback to the .slint declaration.
  2. Re-run the live preview after changing the callback signature.

When it happens

Trigger: Thrown at internal/compiler/generator/rust_live_preview.rs:120 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of slint-ui/slint@3fd8f2ec03 (2026-08-19). Data as JSON: /api/errors/1a6d09e1efbf8634. Report an issue: GitHub.