slint-ui/slint · error
LibGlobal not found
Error message
LibGlobal not found
What it means
This `expect` lives in `mark_library_globals_marks_properties_as_externally_used` (internal/compiler/passes/collect_globals.rs:119), a test helper that searches the document's used globals for the compiler-internal `LibGlobal` global and asserts it is present. `LibGlobal` is a synthetic global the compiler injects; if it is missing from `used_types.globals` at this point, the compiler's global-collection invariant is broken.
Solutions
- Ensure `mark_used_globals` (or the equivalent pass) ran on the document before this lookup so `LibGlobal` is registered as used.
- Keep the `expose_in_public_api`/`is_constant_impl` conditions as the test intends so the marking short-circuit doesn't skip `LibGlobal`.
- Verify the `LibGlobal` id string and injection code in the compiler were not renamed or removed.
- Run `cargo test -p i-slint-compiler collect_globals` to confirm the fix.
Defensive patterns
Strategy: validation
Validate before calling
// Contributors: assert the precondition in tests
assert!(doc.used_types.borrow().globals.iter().any(|g| g.id == "LibGlobal"),
"run mark_used_globals before mark_library_globals"); Prevention
- Always run the global-marking pass before code that reads used_types.globals.
- Don't rename or conditionally skip LibGlobal injection.
- Run the collect_globals unit tests after touching global marking code.
When it happens
Trigger: Running this collect_globals test path (or code sharing its assumption) after `mark_used_globals`/`mark_library_globals` when `LibGlobal` was never collected — e.g. `is_constant_impl` short-circuiting marked properties, global marking skipped for the document, or a contributor change that removed/renamed `LibGlobal` injection.
Common situations: Slint compiler development and CI; changes to global marking or constant evaluation that alter which globals land in `used_types`; test setups that bypass normal document compilation.
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
- Component should cleanly upgrade here
- constraint must have binding
- EmbedTextures builds the shared font collection
- internal compiler error: more than one strong reference…
- named struct declarations have symbol counters
AI-assisted analysis of slint-ui/slint@bb937076de (2026-09-16).
Data as JSON: /api/errors/f4cd0107779c728c.
Report an issue: GitHub.
Appendix: source
Thrown at internal/compiler/passes/collect_globals.rs:119
export component App {
out property <string> text-out: "\{LibGlobal.value} \{LibGlobal.count} \{LibGlobal.ready}";
}
"#
.into(),
Some(std::path::Path::new("test.slint")),
&mut diag,
);
let (mut doc, diag, _) =
spin_on::spin_on(crate::compile_syntax_node(doc_node, diag, compiler_config));
assert!(!diag.has_errors(), "compile error: {:?}", diag.to_string_vec());
let global = doc
.used_types
.borrow()
.globals
.iter()
.find(|g| g.id == "LibGlobal")
.expect("LibGlobal not found")
.clone();
// Simulate a library import by adding `LibGlobal` to `library_exports`
// and re-running `mark_library_globals`. Clear `expose_in_public_api`
// so the `is_constant_impl` short-circuit doesn't mask the result.
doc.library_exports.insert(
"LibGlobal".to_string(),
crate::typeloader::LibraryInfo {
name: "Lib".into(),
package: "lib".into(),
module: None,
exports: Vec::new(),
},
);
for (_, d) in global.root_element.borrow_mut().property_declarations.iter_mut() {
d.expose_in_public_api = false;
}
global.root_element.borrow().property_analysis.borrow_mut().clear();View on GitHub (pinned to bb937076de)