{"record":{"id":"eed9cd06c0586fa4","repo":"slint-ui/slint","slug":"named-struct-declarations-have-symbol-counters","errorCode":null,"errorMessage":"named struct declarations have symbol counters","messagePattern":"named struct declarations have symbol counters","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/compiler/object_tree.rs","lineNumber":3982,"sourceCode":"    let fields: BTreeMap<SmolStr, Type> = object_node\n        .ObjectTypeMember()\n        .map(|member| {\n            let field_name = parser::identifier_text(&member).unwrap_or_default();\n            field_order.push(field_name.clone());\n            let field_ty = type_from_node(member.Type(), diag, tr);\n            if let Some(default_value_node) = member.Expression() {\n                if name.is_none() {\n                    diag.push_error(\n                        \"Field default values are only supported in named struct declarations\"\n                            .into(),\n                        &default_value_node,\n                    );\n                } else if let Some(expr) = resolve_struct_field_default_value(\n                    default_value_node,\n                    &field_ty,\n                    diag,\n                    tr,\n                    symbol_counters.expect(\"named struct declarations have symbol counters\"),\n                ) {\n                    field_defaults.insert(field_name.clone(), expr);\n                }\n            }\n            (field_name, field_ty)\n        })\n        .collect();\n    // The `@rust-attr` attributes and the declaration node live on the\n    // enclosing `StructDeclaration` (the parent of the `ObjectType`).\n    let struct_decl = object_node.parent();\n    Type::Struct(Arc::new(Struct {\n        fields,\n        field_defaults,\n        name: name.map_or(StructName::None, |name| {\n            let rust_attributes = struct_decl\n                .as_ref()\n                .and_then(|p| syntax_nodes::StructDeclaration::new(p.clone()))\n                .map(|d| d.AtRustAttr().map(|a| SmolStr::from(a.text().to_string())).collect())","sourceCodeStart":3964,"sourceCodeEnd":4000,"githubUrl":"https://github.com/slint-ui/slint/blob/3a7e700487dc74d404cad0726378053ab763d4e0/internal/compiler/object_tree.rs#L3964-L4000","documentation":"This panic fires in object_tree.rs:3916 when resolving default values for fields of a named struct declaration. `resolve_struct_field_default_value` requires the `symbol_counters` parameter to track unique identifiers, and the code asserts that named struct declarations always have counters available. A `None` here means the struct being processed was not registered with symbol counters, which the compiler treats as an impossible state.","triggerScenarios":"Compiling a .slint file containing a named `struct` declaration with a field default value, while the `symbol_counters` slot passed down is `None` — i.e. the struct was not created through the path that allocates counters (e.g. struct defined in a context where counters were not initialized, or a compiler pass ordering regression).","commonSituations":"Compiler development/refactoring around named struct declarations and default values; using an in-development Slint nightly with a pass-ordering regression; .slint files with struct field defaults processed through an unusual import/preprocessing path.","solutions":["Simplify: remove the default value expression from the struct field declaration and assign defaults at the property/binding site instead.","Check whether the .slint file compiles with the latest stable Slint release; upgrade the slint compiler crate.","If you are a compiler contributor, ensure the code path creating the named struct allocates symbol counters before default-value resolution runs.","File a minimal reproducer as a compiler bug if it persists."],"exampleFix":"// before\nstruct Data { count: int = 1; }\n// after\nstruct Data { count: int; }\nproperty <Data> d: { count: 1 };","handlingStrategy":"validation","validationCode":"// Avoid the risky pattern in user code: no default values on named struct fields\nfn has_struct_field_defaults(src: &str) -> bool {\n    src.lines().any(|l| l.contains(\":\") && l.trim_end().ends_with(\"= ...;\"))\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Don't rely on struct field default values; assign defaults at binding/property sites.","Use released Slint versions for production compiles.","Contributors: allocate symbol counters for every named struct before default-value resolution."],"tags":["rust","compiler","internal-panic","slint"],"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"}