{"record":{"id":"60cf22c5d5073335","repo":"slint-ui/slint","slug":"there-should-be-a-popup-menu-if-we-want-to-show-it-rust","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/rust.rs","lineNumber":4750,"sourceCode":"                )\n            } else {\n                panic!(\"internal error: invalid args to ClosePopupWindow {arguments:?}\")\n            }\n        }\n        BuiltinFunction::ShowPopupMenu | BuiltinFunction::ShowPopupMenuInternal => {\n            let [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\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 =\n                inner_component_id(&ctx.compilation_unit.sub_components[popup.item_tree.root]);\n            let window_adapter_tokens = access_window_adapter_field(ctx);\n\n            let popup_ctx = EvaluationContext::new_sub_component(\n                ctx.compilation_unit,\n                popup.item_tree.root,\n                RustGeneratorContext { global_access: quote!(_self.globals()) },\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            let close_popup = context_menu.clone().then(|context_menu| quote!{\n                if let Some(current_id) = #context_menu.popup_id.take() {\n                    sp::WindowInner::from_pub(#window_adapter_tokens.window()).close_popup(current_id);","sourceCodeStart":4732,"sourceCodeEnd":4768,"githubUrl":"https://github.com/slint-ui/slint/blob/3a7e700487dc74d404cad0726378053ab763d4e0/internal/compiler/generator/rust.rs#L4732-L4768","documentation":"Rust generator mirror of the C++ popup-menu panic: compiling the builtin `show-popup-menu` call requires `ctx.compilation_unit.popup_menu` to hold the auto-generated popup menu item tree. A None value panics because the builtin cannot be lowered without the popup menu component registered by an earlier compiler pass.","triggerScenarios":"`compile_builtin_function_call` lowers a `show_popup_menu` call in a unit where `popup_menu` was never collected — the collection pass did not run (e.g. a partial pipeline like LSP or tooling), or registration failed upstream.","commonSituations":"Compiler/tooling development: running codegen on units that skipped the popup-menu registration pass; refactoring how builtin functions register their supporting item trees.","solutions":["Run the pass that populates `CompilationUnit::popup_menu` before code generation","Assert earlier (at unit finalization) that any `show_popup_menu` usage implies a registered popup menu","Return a clear compile diagnostic instead of panicking when the popup menu is missing"],"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 used but compilation_unit.popup_menu was never registered\"));","handlingStrategy":"validation","validationCode":"if ctx.compilation_unit.popup_menu.is_none() {\n    panic!(\"show_popup_menu lowered but popup_menu never registered in this unit\");\n}","typeGuard":"let popup_menu = match ctx.compilation_unit.popup_menu.as_ref() {\n    Some(p) => p,\n    None => panic!(\"cannot lower show_popup_menu: no popup menu item tree registered\"),\n};","tryCatchPattern":null,"preventionTips":["Ensure popup-menu registration precedes rust codegen in every pipeline","Add a pipeline-final assertion tying show_popup_menu usage to registration","Test show-popup-menu lowering via the rust generator in CI","Mirror the check in C++ and Rust generators to catch regressions early"],"tags":["compiler","rust-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"}