slint-ui/slint · error

invalid parent reference

Error message

invalid parent reference

What it means

While lowering an expression in a sub-component scope, walking `parent_level` levels up ran past the root of the parent chain. The parent reference was exhausted but more levels were requested — an invalid or inconsistent parent_level was computed.

Solutions

  1. Fix the user code so it does not climb above the root component (remove extra `parent.` hops)
  2. In compiler code, verify `parent_level` computation matches the actual sub-component chain depth before lowering
  3. Add a diagnostic in an earlier pass that rejects out-of-range parent references with a user-facing error

Example fix

// .slint user code — before
root-level element referencing parent.parent  // exceeds depth
// after
reference only existing parent levels, e.g. `parent` once at most from a child
Defensive patterns

Strategy: validation

Validate before calling

if parent_level > depth_of(sc) { return Err("parent reference exceeds nesting depth"); }

Prevention

When it happens

Trigger: A binding or expression uses `parent` (or `100%` sizing via parent references) across more levels than the element's actual nesting depth, e.g. `parent.parent` inside the root sub-component, or a pass that mis-computes `parent_level` for a two-way binding in a deeply repeated subtree.

Common situations: User .slint code referencing `parent` at the top-level component; compiler passes counting parent hops wrongly after repeater/sub-component refactorings.

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@bb937076de (2026-09-16). Data as JSON: /api/errors/d3330cbce346cdbb. Report an issue: GitHub.

Appendix: source

Thrown at internal/compiler/llr/expression.rs:1119

            cu: &super::CompilationUnit,
            sc: SubComponentIdx,
            parent: Option<&ParentScope<'_>>,
            path: &[SubComponentInstanceIdx],
            f: impl FnOnce(ParentScope<'_>) -> R,
        ) -> R {
            if let [first, rest @ ..] = path {
                let ps = ParentScope { sub_component: sc, repeater_index: None, parent };
                let child = cu.sub_components[sc].sub_components[*first].ty;
                descend(cu, child, Some(&ps), rest, f)
            } else {
                f(ParentScope { sub_component: sc, repeater_index: None, parent })
            }
        }
        let EvaluationScope::SubComponent(mut sc, mut parent) = self.current_scope else {
            panic!("not in a sub-component scope")
        };
        for _ in 0..parent_level {
            let p = parent.expect("invalid parent reference");
            sc = p.sub_component;
            parent = p.parent;
        }
        descend(self.compilation_unit, sc, parent, sub_component_path, f)
    }

    pub fn current_sub_component(&self) -> Option<&super::SubComponent> {
        let EvaluationScope::SubComponent(i, _) = self.current_scope else { return None };
        self.compilation_unit.sub_components.get(i)
    }

    pub fn current_global(&self) -> Option<&super::GlobalComponent> {
        let EvaluationScope::Global(i) = self.current_scope else { return None };
        self.compilation_unit.globals.get(i)
    }

    pub fn parent_sub_component_idx(&self, parent: usize) -> Option<SubComponentIdx> {
        let EvaluationScope::SubComponent(mut sc, mut par) = self.current_scope else {

View on GitHub (pinned to bb937076de)