slint-ui/slint · error

parent_level should be valid

Error message

parent_level should be valid

What it means

`resolve_model` walks `parent_level` hops up the sub-component parent chain of a repeated element's two-way model binding. The panic means the chain ended (par became None) before consuming all requested hops.

Solutions

  1. Correct the parent_level computation in the pass that resolves model two-way bindings
  2. Reject over-deep parent references in an earlier validation pass with a proper diagnostic
  3. Reduce the .slint input that triggers it and file a compiler bug

Example fix

// before
for _ in 0..*parent_level {
    let x = par.expect("parent_level should be valid");
// after
for _ in 0..*parent_level {
    let Some(x) = par else {
        return None; // or emit a compile error: parent_level exceeds nesting depth
    };
Defensive patterns

Strategy: validation

Validate before calling

if *parent_level > parent_chain_len(ctx.current_scope) { return None; }

Prevention

When it happens

Trigger: A `for`-loop's model declared a two-way binding whose `parent_level` exceeds the actual nesting depth of the repeated item's sub-component chain.

Common situations: Compiler passes computing parent levels for model two-way bindings after refactoring repeaters; user code with invalid deep parent references inside `for` loops.

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


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

Appendix: source

Thrown at internal/compiler/llr/item_tree.rs:334

    /// Resolve the parent walk and the data/index/repeater references of a
    /// model two-way binding. Returns `None` for regular property bindings.
    pub fn resolve_model<'a, T>(
        &self,
        ctx: &EvaluationContext<'a, T>,
    ) -> Option<ResolvedModelTwoWayBinding<'a>> {
        let index_prop = self.is_model?;
        let MemberReference::Relative { parent_level, local_reference } = &self.prop2 else {
            unreachable!("model two-way binding's prop2 is always a Relative reference")
        };
        debug_assert!(local_reference.sub_component_path.is_empty());
        let LocalMemberIndex::Property(data_prop) = local_reference.reference else {
            unreachable!("model two-way binding's prop2 always references a property")
        };
        let super::EvaluationScope::SubComponent(mut sc, mut par) = ctx.current_scope else {
            unreachable!("model two-way binding cannot be in a global")
        };
        for _ in 0..*parent_level {
            let x = par.expect("parent_level should be valid");
            par = x.parent;
            sc = x.sub_component;
        }
        let par = par.expect("repeated item_tree must have a parent");
        let data_prop_ty = &ctx.compilation_unit.sub_components[sc].properties[data_prop].ty;
        Some(ResolvedModelTwoWayBinding {
            parent_level: *parent_level,
            body_sub_component: sc,
            data_prop,
            data_prop_ty,
            index_prop,
            parent_sub_component: par.sub_component,
            repeater_index: par.repeater_index.expect("repeated parent has a repeater_index"),
        })
    }
}

#[derive(Debug, Default, Clone)]

View on GitHub (pinned to 3a7e700487)