{"record":{"id":"85a4ef58ef168d61","repo":"slint-ui/slint","slug":"root-component-called-on-a-definition-built-without-compiler","errorCode":null,"errorMessage":"root_component() called on a definition built without compiler state","messagePattern":"root_component\\(\\) called on a definition built without compiler state","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/interpreter/api.rs","lineNumber":1557,"sourceCode":"\n    /// True if instances of this component expose a `slint::Window`-shaped API\n    /// (i.e. calling [`ComponentInstance::window`] is meaningful). False for\n    /// non-windowed roots such as `SystemTrayIcon`, where `window()` would panic.\n    #[doc(hidden)]\n    #[cfg(feature = \"internal\")]\n    pub fn is_window(&self) -> bool {\n        self.inner.top_level_type() == i_slint_compiler::llr::TopLevelComponentType::Window\n    }\n\n    /// This gives access to the tree of Elements.\n    #[cfg(feature = \"internal\")]\n    #[doc(hidden)]\n    pub fn root_component(&self) -> Rc<i_slint_compiler::object_tree::Component> {\n        self.inner\n            .type_loaders\n            .originals\n            .get(self.inner.public_index)\n            .expect(\"root_component() called on a definition built without compiler state\")\n            .clone()\n    }\n\n    /// Return the `TypeLoader` used when parsing the code in the interpreter.\n    ///\n    /// WARNING: this is not part of the public API\n    #[cfg(feature = \"internal-highlight\")]\n    pub fn type_loader(&self) -> std::rc::Rc<i_slint_compiler::typeloader::TypeLoader> {\n        self.inner.type_loaders.type_loader.clone().expect(\n            \"TypeLoader was not retained for this ComponentDefinition (reconstructed from an instance)\",\n        )\n    }\n\n    /// Return the `TypeLoader` used when parsing the code in the interpreter in\n    /// a state before most passes were applied by the compiler.\n    ///\n    /// Each returned type loader is a deep copy of the entire state connected to it,\n    /// so this is a fairly expensive function!","sourceCodeStart":1539,"sourceCodeEnd":1575,"githubUrl":"https://github.com/slint-ui/slint/blob/3a7e700487dc74d404cad0726378053ab763d4e0/internal/interpreter/api.rs#L1539-L1575","documentation":"`ComponentDefinition::root_component()` exposes the compiler's `object_tree::Component`, but only if the definition was produced by actual compilation. When the definition came from a source built without compiler state (e.g. created programmatically or from a pre-compiled artifact where `type_loaders.originals` has no entry for `public_index`), the map lookup fails and the code panics. The method is `#[doc(hidden)]` and explicitly not part of the public API contract for such definitions.","triggerScenarios":"Calling the `#[doc(hidden)]` `root_component()` on a `ComponentDefinition` obtained from a code path that did not parse/compile `.slint` source with the interpreter's `TypeLoader` — e.g. a definition built for a compiled-binary (Rust macro / pre-compiled) component where `originals` was never populated.","commonSituations":"Hit by downstream projects that use the interpreter's internal APIs to introspect components loaded from `slint::include_modules!` style pre-compiled definitions instead of `slint_interpreter::compile` results.","solutions":["Only call `root_component()` on definitions returned from the interpreter's `compile()` APIs","Check the definition provenance before introspection; use the public interpreter API (`component_instance`, `set_property`) instead of compiler internals","If you need compiler-level access to a pre-compiled component, compile the source with the interpreter instead of using the macro path","Remove reliance on `#[doc(hidden)]` APIs — they can panic and change without notice"],"exampleFix":"// before\nlet root = definition.root_component(); // may panic\n// after\n// only for interpreter-compiled definitions:\nlet (doc, diag, _) = slint_interpreter::compile(\n    std::rc::Rc::new(source.into()), None, Default::default(),\n).unwrap();\nlet root = doc.components.last().unwrap().clone();","handlingStrategy":"type-guard","validationCode":"// only call root_component on definitions from slint_interpreter::compile\nlet from_interpreter = matches!(source, Source::InterpreterCompiled);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never rely on `#[doc(hidden)]` APIs for non-interpreter-compiled definitions","Check the definition's provenance before introspecting compiler internals","Prefer the public interpreter API (set_property/get_property) over compiler object-tree access"],"tags":["interpreter","rust","panic","internal-api"],"backgroundTag":"internal-invariant-violation","analyzedSha":"3a7e700487dc74d404cad0726378053ab763d4e0","analyzedAt":"2026-09-16T01:37:20.251Z","contentChangedAt":"2026-09-16T01:37:20.251Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}