{"record":{"id":"9316ecddbe570e7f","repo":"slint-ui/slint","slug":"slint-testing-use-native-popup-called-without-test","errorCode":null,"errorMessage":"slint_testing_use_native_popup called without testing backend/adapter","messagePattern":"slint_testing_use_native_popup called without testing backend/adapter","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/backends/testing/ffi.rs","lineNumber":82,"sourceCode":"}\n\n#[unsafe(no_mangle)]\npub extern \"C\" fn slint_send_keyboard_string_sequence(\n    sequence: &SharedString,\n    window_adapter: &WindowAdapterRc,\n) {\n    crate::testing_backend::send_keyboard_string_sequence(sequence, window_adapter);\n}\n\n#[unsafe(no_mangle)]\npub extern \"C\" fn slint_testing_use_native_popup(window_adapter: &WindowAdapterRc, native: bool) {\n    window_adapter\n        .internal(i_slint_core::InternalToken)\n        .and_then(|wa| {\n            (wa as &dyn core::any::Any).downcast_ref::<crate::testing_backend::TestingWindow>()\n        })\n        .map(|testing_window| testing_window.use_native_popup(native))\n        .expect(\"slint_testing_use_native_popup called without testing backend/adapter\");\n}\n\n#[unsafe(no_mangle)]\npub extern \"C\" fn slint_testing_active_popup_count(window_adapter: &WindowAdapterRc) -> usize {\n    WindowInner::from_pub(window_adapter.window()).active_popups().len()\n}\n\n#[unsafe(no_mangle)]\npub unsafe extern \"C\" fn slint_testing_element_visit_elements(\n    root: &ItemTreeRc,\n    user_data: *mut c_void,\n    visitor: unsafe extern \"C\" fn(*mut c_void, &ElementHandle) -> bool,\n) -> bool {\n    RootWrapper(root)\n        .root_element()\n        .query_descendants()\n        .match_predicate(move |element| unsafe { visitor(user_data, element) })\n        .find_first()","sourceCodeStart":64,"sourceCodeEnd":100,"githubUrl":"https://github.com/slint-ui/slint/blob/bb937076de3f7919766c1f25e2e969367cf77e9a/internal/backends/testing/ffi.rs#L64-L100","documentation":"The testing backend's FFI helper `slint_testing_use_native_popup` downcasts the given `WindowAdapterRc` to the `TestingWindow` adapter and panics if the downcast fails. This means the popup native-flag test API was invoked on a window that is not backed by the Slint testing backend (e.g. the winit or Qt backend is active instead).","triggerScenarios":"Calling the internal FFI `slint_testing_use_native_popup` (used by Slint test infrastructure to force native popups) when the process's window adapter is the platform's real backend adapter rather than `crate::testing_backend::TestingWindow`.","commonSituations":"Running Slint tests without first initializing the testing backend (missing `slint_testing::init()` or `init_no_event_loop()`); a test binary that links the real backend (winit/qt) via feature selection; calling the helper after the platform was initialized with a different adapter.","solutions":["Initialize the testing backend before any window is created: call `slint_testing::init()` (or `init_no_event_loop()` / `init_integration_test_*`) at test start.","Ensure only the testing backend feature is enabled in the test build so the platform adapter is TestingWindow.","Verify the window adapter you pass is the one created after testing-backend init, not one captured earlier from a real backend."],"exampleFix":"// before\n#[test]\nfn popup_test() {\n    // no testing backend init -> panics\n    slint_testing_use_native_popup(&adapter, true);\n}\n\n// after\n#[test]\nfn popup_test() {\n    slint_testing::init_no_event_loop(); // installs TestingWindow adapter\n    slint_testing_use_native_popup(&adapter, true);\n}","handlingStrategy":"validation","validationCode":"// before calling popup test helpers, ensure testing backend is active\nfn testing_backend_active() -> bool {\n    std::env::var(\"SLINT_BACKEND\").map(|b| b.is_empty() || b == \"testing\").unwrap_or(true)\n    // plus: init was called first — enforce via Once in your test harness\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always call slint_testing::init*() before creating any Slint window in tests","Keep the testing backend as the only enabled backend in test builds","Do not mix real-backend runs with testing-backend-only test helpers"],"tags":["testing","backend","popup","downcast"],"backgroundTag":"type-mismatch","analyzedSha":"bb937076de3f7919766c1f25e2e969367cf77e9a","analyzedAt":"2026-09-16T01:37:20.251Z","contentChangedAt":"2026-09-16T01:37:20.251Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}