{"record":{"id":"b360d110e31320f7","repo":"slint-ui/slint","slug":"there-should-be-a-popup-menu-if-we-want-to-show-it","errorCode":null,"errorMessage":"there should be a popup menu if we want to show it","messagePattern":"there should be a popup menu if we want to show it","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/compiler/generator/cpp.rs","lineNumber":5453,"sourceCode":"                component_access.then(|component_access| format!(\"{component_access}->{compo_path}globals->window().window_handle().close_popup({component_access}->{compo_path}popup_id_{popup_index})\"))\n            } else {\n                panic!(\"internal error: invalid args to ClosePopupWindow {arguments:?}\")\n            }\n        }\n\n        BuiltinFunction::ShowPopupMenu | BuiltinFunction::ShowPopupMenuInternal => {\n            let [llr::Expression::PropertyReference(context_menu_ref), entries, position] = arguments\n            else {\n                panic!(\"internal error: invalid args to ShowPopupMenu {arguments:?}\")\n            };\n\n            let context_menu = access_member(context_menu_ref, ctx);\n            let position = compile_expression(position, ctx);\n            let popup = ctx\n                .compilation_unit\n                .popup_menu\n                .as_ref()\n                .expect(\"there should be a popup menu if we want to show it\");\n            let popup_id = ident(&ctx.compilation_unit.sub_components[popup.item_tree.root].name);\n            let window = access_window_field(ctx);\n\n            let popup_ctx = EvaluationContext::new_sub_component(\n                ctx.compilation_unit,\n                popup.item_tree.root,\n                CppGeneratorContext { global_access: \"self->globals\".into(), conditional_includes: ctx.generator_state.conditional_includes },\n                None,\n            );\n            let access_entries = access_member(&popup.entries, &popup_ctx).unwrap();\n            let access_sub_menu = access_member(&popup.sub_menu, &popup_ctx).unwrap();\n            let access_activated = access_member(&popup.activated, &popup_ctx).unwrap();\n            let access_close = access_member(&popup.close, &popup_ctx).unwrap();\n\n            item_owner(context_menu_ref).then_named(\"context_menu_owner\", |owner| {\n            let (_, context_menu_rc) = native_item_from_owner(context_menu_ref, ctx, owner);\n            let close_popup = context_menu.then(|context_menu| {\n                format!(\"{window}.close_popup({context_menu}.popup_id)\")","sourceCodeStart":5435,"sourceCodeEnd":5471,"githubUrl":"https://github.com/slint-ui/slint/blob/3a7e700487dc74d404cad0726378053ab763d4e0/internal/compiler/generator/cpp.rs#L5435-L5471","documentation":"When the C++ generator compiles the builtin `show-popup-menu` function, it expects `ctx.compilation_unit.popup_menu` to be `Some`. The compiler populates `popup_menu` exactly when a popup menu is used in the compilation unit, so a None here means the `show_popup_menu` builtin is being generated without the supporting popup-menu item tree having been registered.","triggerScenarios":"Compiling a call to `show-popup-menu` in a compilation unit where the `popup_menu` field was never set — e.g. the register_builtin_evaluation_functions/pass that collects the popup menu did not run or ran after codegen, or the popup menu declaration failed to register.","commonSituations":"Compiler development: changes to how `popup_menu` is collected on the CompilationUnit; partial compilation pipelines (LSP, live-preview) that skip the collection pass.","solutions":["Ensure the compilation pass that registers the popup menu item tree runs before C++ code generation","Check that `compilation_unit.popup_menu` is populated whenever `show_popup_menu` appears in the expression set","Replace the expect with a compile error diagnostic pointing at the missing popup menu declaration"],"exampleFix":"// before\nlet popup = ctx.compilation_unit.popup_menu.as_ref().expect(\"there should be a popup menu if we want to show it\");\n// after\nlet popup = ctx.compilation_unit.popup_menu.as_ref().unwrap_or_else(||\n    panic!(\"show_popup_menu called but no popup menu was registered in this compilation unit\"));","handlingStrategy":"validation","validationCode":"if ctx.compilation_unit.popup_menu.is_none() {\n    panic!(\"show_popup_menu generated but no popup menu registered in this compilation unit\");\n}","typeGuard":"let popup_menu = match ctx.compilation_unit.popup_menu.as_ref() {\n    Some(p) => p,\n    None => panic!(\"popup menu not registered; run the popup-menu collection pass first\"),\n};","tryCatchPattern":null,"preventionTips":["Verify the popup-menu collection pass runs before all code generators","Add an end-of-pipeline assertion: show_popup_menu usage implies popup_menu registered","Cover popup-menu codegen in both C++ and Rust generator tests","When adding tooling pipelines (LSP, preview), include the popup-menu registration pass"],"tags":["compiler","cpp-codegen","popups","internal-invariant"],"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"}