{"record":{"id":"317fa5ce0468698f","repo":"slint-ui/slint","slug":"invalid-type-in-public-properties","errorCode":null,"errorMessage":"Invalid type in public properties","messagePattern":"Invalid type in public properties","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/compiler/generator/cpp.rs","lineNumber":3771,"sourceCode":"            ];\n            declarations.push((\n                Access::Public,\n                Declaration::Function(Function {\n                    name: accessor_names::cpp_accessor_name(name, AccessorKind::Invoker),\n                    signature: format!(\n                        \"({}) const -> {ret}\",\n                        param_types\n                            .iter()\n                            .enumerate()\n                            .map(|(i, ty)| format!(\"{ty} arg_{i}\"))\n                            .join(\", \"),\n                    ),\n                    statements: Some(call_code),\n                    ..Default::default()\n                }),\n            ));\n        } else {\n            let cpp_property_type = p.ty.cpp_type().expect(\"Invalid type in public properties\");\n            let prop_getter: Vec<String> = vec![\n                \"slint::private_api::assert_main_thread();\".into(),\n                \"[[maybe_unused]] auto self = this;\".into(),\n                format!(\"return {}.get();\", access),\n            ];\n            declarations.push((\n                Access::Public,\n                Declaration::Function(Function {\n                    name: accessor_names::cpp_accessor_name(name, AccessorKind::Getter),\n                    signature: format!(\"() const -> {cpp_property_type}\"),\n                    statements: Some(prop_getter),\n                    ..Default::default()\n                }),\n            ));\n\n            if !p.read_only() {\n                let prop_setter: Vec<String> = vec![\n                    \"slint::private_api::assert_main_thread();\".into(),","sourceCodeStart":3753,"sourceCodeEnd":3789,"githubUrl":"https://github.com/slint-ui/slint/blob/3a7e700487dc74d404cad0726378053ab763d4e0/internal/compiler/generator/cpp.rs#L3753-L3789","documentation":"In the C++ generator, public API is emitted only for property types that have a C++ representation. `p.ty.cpp_type()` returned None for a property included in the public API, so the generator panics. Only types mapped to C++ (int, float, bool, string, color, brushes, structs, models, etc.) may appear in a public component/global API.","triggerScenarios":"A property or callback declared public whose Slint type has no `cpp_type()` mapping — e.g. an exotic internal type, a pure-layout type, or a newly added language type not yet mapped for C++ — is processed by `generate_public_api_for_properties` / the live-preview declaration path.","commonSituations":"Slint development: adding a new builtin type to the compiler and forgetting to extend `cpp_type()`; declaring public properties with types that are only valid internally; version drift between compiler types and the C++ generator.","solutions":["Extend `Type::cpp_type()` in the compiler to map the missing type to a C++ type","Remove the property from the public API or change its declared type to a C++-supported one","Reproduce with the offending .slint file, identify the property type, and add a mapping or a compile-time rejection with a friendly diagnostic instead of an expect"],"exampleFix":"// before\nlet cpp_property_type = p.ty.cpp_type().expect(\"Invalid type in public properties\");\n// after\nlet cpp_property_type = p.ty.cpp_type().unwrap_or_else(||\n    panic!(\"property '{}' of type {:?} cannot be exposed to C++\", prop_name, p.ty));","handlingStrategy":"validation","validationCode":"fn is_cpp_expressible(ty: &Type) -> bool {\n    !matches!(ty, Type::Invalid | Type::Void) && ty.cpp_type().is_some()\n}\n// assert every public property passes is_cpp_expressible before codegen","typeGuard":"fn assert_public_property_cpp_support(name: &str, ty: &Type) {\n    assert!(ty.cpp_type().is_some(), \"public property '{name}' has no C++ type mapping ({ty:?})\");\n}","tryCatchPattern":null,"preventionTips":["Extend cpp_type() whenever a new builtin type is added","Keep a test that generates C++ public API for every supported property type","Reject non-mappable types at compile time with a diagnostic, not an expect","Check the type before declaring a property public in .slint"],"tags":["compiler","cpp-codegen","type-system","public-api"],"backgroundTag":"type-mismatch","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"}