slint-ui/slint · error
reference to invalid arg
Error message
reference to invalid arg
What it means
This panic fires in `substitute_arguments_recursive` (internal/compiler/passes/const_propagation.rs:491) while inlining a function during constant propagation. When the function body contains an `Expression::FunctionParameterReference { index, .. }`, the code looks up the corresponding argument by index in the supplied `arguments` slice; an out-of-range index means the caller supplied fewer arguments than the function body references — a broken function signature/body invariant.
Solutions
- Check the .slint function: ensure the call site passes as many arguments as the function declares parameters, with matching types.
- Rebuild with the latest stable Slint compiler; nightly regressions in const propagation are possible.
- Simplify the inlined function (reduce parameters / avoid calling it from constant contexts) as a workaround.
- Contributors: assert `arguments.len()` equals the function's parameter count at `try_inline_function` entry to fail earlier with a clearer message.
Example fix
// before
function f(a: int, b: int) -> int { return a + b; }
f(1); // mismatch feeds a stale body/signature
// after
f(1, 2); Defensive patterns
Strategy: validation
Validate before calling
// Pre-check call arity before compiling (lint in build tooling)
fn call_arity_matches(src: &str, name: &str, params: usize) -> Result<(), String> {
// scan for `name(` and count top-level comma-separated args; must equal params
Ok(())
} Prevention
- Always pass exactly as many arguments as the .slint function declares parameters.
- Keep parameter lists stable; change call sites together with signatures.
- Contributors: validate argument count at try_inline_function entry and emit a diagnostic, not a panic.
When it happens
Trigger: Calling `try_inline_function` (directly or via recursion) with an `arguments` slice shorter than the number of parameters the function body references — e.g. after a pass mutated the function's parameter list without updating call sites, or an inline attempt on a function resolved from a mismatched type/declaration.
Common situations: Slint compiler development changing function inlining or parameter handling; .slint functions whose declared parameters were altered by an earlier pass; nightly regressions in const propagation of function calls.
Related errors
- Component should cleanly upgrade here
- constraint must have binding
- EmbedTextures builds the shared font collection
- internal compiler error: more than one strong reference…
- LibGlobal not found
AI-assisted analysis of slint-ui/slint@bb937076de (2026-09-16).
Data as JSON: /api/errors/3d8f588365aaaac6.
Report an issue: GitHub.
Appendix: source
Thrown at internal/compiler/passes/const_propagation.rs:491
fn try_inline_function(
function: &Callable,
arguments: &[Expression],
ga: &GlobalAnalysis,
cache: &mut ConstPropCache,
) -> Option<Expression> {
let function = match function {
Callable::Function(function) => function,
Callable::Builtin(b) => return try_inline_builtin_function(b, arguments, ga),
_ => return None,
};
if !function.is_constant() {
return None;
}
let mut body = extract_constant_property_reference(function, ga, cache)?;
fn substitute_arguments_recursive(e: &mut Expression, arguments: &[Expression]) {
if let Expression::FunctionParameterReference { index, ty } = e {
let e_new = arguments.get(*index).expect("reference to invalid arg").clone();
debug_assert_eq!(e_new.ty(), *ty);
*e = e_new;
} else {
e.visit_mut(|e| substitute_arguments_recursive(e, arguments));
}
}
substitute_arguments_recursive(&mut body, arguments);
if simplify_expression(&mut body, ga, cache) { Some(body) } else { None }
}
fn try_inline_builtin_function(
b: &BuiltinFunction,
args: &[Expression],
ga: &GlobalAnalysis,
) -> Option<Expression> {
let a = |idx: usize| -> Option<f64> {
match args.get(idx)? {View on GitHub (pinned to bb937076de)