slint-ui/slint · error

First argument not an array

Error message

First argument not an array: {:?}

What it means

The interpreter's builtin ArrayRemove function requires its first argument to evaluate to a Value::Model (an array). If the evaluated first argument is any other Value kind (number, string, struct, etc.), the interpreter panics. There is no dynamic coercion to arrays in Slint's type system.

Solutions

  1. Declare the first argument's property/parameter with an explicit array type, e.g. `property<[int]> items;` or `property<[MyStruct]> list;`
  2. Fix the call site so a genuine array is passed to ArrayRemove
  3. Check the .slint source at runtime with a type-aware editor or the LSP to catch the type mismatch statically before running

Example fix

// before (.slint)
property<int> count;
ArrayRemove(count, index); // panics
// after
property<[int]> items;
ArrayRemove(items, index);
Defensive patterns

Strategy: type-guard

Validate before calling

// .slint: declare the argument as an array type
property<[int]> items; // ArrayRemove(items, i) is valid

Type guard

// .slint has no runtime type guard; enforce statically by typing the property:
// property<[T]> items; and only pass properties of type [T] to ArrayRemove

Prevention

When it happens

Trigger: Calling `ArrayRemove(x, i)` from .slint code where x is not an array/model-typed expression — e.g. passing a struct, a plain value, or a property that was expected to be an array but is a different type.

Common situations: Type errors in .slint scripts that the interpreter catches only at runtime; a property declared without array type but used with array builtins; refactoring that changed a property from an array to a scalar while call sites remained.

Understand the failure class

Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.

Related errors


AI-assisted analysis of slint-ui/slint@3a7e700487 (2026-09-16). Data as JSON: /api/errors/374d8e2013577b1c. Report an issue: GitHub.

Appendix: source

Thrown at internal/interpreter/eval.rs:2193

            };
            let value = eval_expression(ctx, &arguments[1]);

            i_slint_core::model::report_model_error(
                "push",
                log_message_location(source_location),
                model.push_row(value),
            );

            Value::Void
        }
        BuiltinFunction::ArrayRemove => {
            if arguments.len() != 2 {
                panic!("internal error: incorrect argument count to ArrayRemove")
            }

            let model = match eval_expression(ctx, &arguments[0]) {
                Value::Model(m) => m,
                _ => panic!("First argument not an array: {:?}", arguments[0]),
            };
            let index = match eval_expression(ctx, &arguments[1]) {
                Value::Number(i) => i,
                _ => panic!("Second argument not an integer: {:?}", arguments[1]),
            };

            let result = match usize::try_from(index as i64) {
                Ok(index) => model.remove_row(index),
                Err(_) => Err(i_slint_core::model::ModelError::out_of_bounds(model.row_count())),
            };
            i_slint_core::model::report_model_error(
                "remove",
                log_message_location(source_location),
                result,
            );

            Value::Void
        }

View on GitHub (pinned to 3a7e700487)