{"record":{"id":"3d8f588365aaaac6","repo":"slint-ui/slint","slug":"reference-to-invalid-arg","errorCode":null,"errorMessage":"reference to invalid arg","messagePattern":"reference to invalid arg","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/compiler/passes/const_propagation.rs","lineNumber":491,"sourceCode":"fn try_inline_function(\n    function: &Callable,\n    arguments: &[Expression],\n    ga: &GlobalAnalysis,\n    cache: &mut ConstPropCache,\n) -> Option<Expression> {\n    let function = match function {\n        Callable::Function(function) => function,\n        Callable::Builtin(b) => return try_inline_builtin_function(b, arguments, ga),\n        _ => return None,\n    };\n    if !function.is_constant() {\n        return None;\n    }\n    let mut body = extract_constant_property_reference(function, ga, cache)?;\n\n    fn substitute_arguments_recursive(e: &mut Expression, arguments: &[Expression]) {\n        if let Expression::FunctionParameterReference { index, ty } = e {\n            let e_new = arguments.get(*index).expect(\"reference to invalid arg\").clone();\n            debug_assert_eq!(e_new.ty(), *ty);\n            *e = e_new;\n        } else {\n            e.visit_mut(|e| substitute_arguments_recursive(e, arguments));\n        }\n    }\n    substitute_arguments_recursive(&mut body, arguments);\n\n    if simplify_expression(&mut body, ga, cache) { Some(body) } else { None }\n}\n\nfn try_inline_builtin_function(\n    b: &BuiltinFunction,\n    args: &[Expression],\n    ga: &GlobalAnalysis,\n) -> Option<Expression> {\n    let a = |idx: usize| -> Option<f64> {\n        match args.get(idx)? {","sourceCodeStart":473,"sourceCodeEnd":509,"githubUrl":"https://github.com/slint-ui/slint/blob/bb937076de3f7919766c1f25e2e969367cf77e9a/internal/compiler/passes/const_propagation.rs#L473-L509","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nfunction f(a: int, b: int) -> int { return a + b; }\nf(1); // mismatch feeds a stale body/signature\n// after\nf(1, 2);","handlingStrategy":"validation","validationCode":"// Pre-check call arity before compiling (lint in build tooling)\nfn call_arity_matches(src: &str, name: &str, params: usize) -> Result<(), String> {\n    // scan for `name(` and count top-level comma-separated args; must equal params\n    Ok(())\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["rust","compiler","internal-panic","function-inlining"],"backgroundTag":"index-out-of-range","analyzedSha":"bb937076de3f7919766c1f25e2e969367cf77e9a","analyzedAt":"2026-09-16T01:37:20.251Z","contentChangedAt":"2026-09-16T01:37:20.251Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}