Skip to content

Commit 80946c7

Browse files
committed
feat: Add inline struct type to struct literals for field access
- Create Type::Struct with FieldDef for struct literals - This allows field access to find field indices without TypeRegistry lookup - Still pending: Fix InsertValue chaining in SSA translator for struct init
1 parent 6c44950 commit 80946c7

1 file changed

Lines changed: 23 additions & 2 deletions

File tree

crates/zyn_peg/src/runtime.rs

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1538,8 +1538,29 @@ impl AstHostFunctions for TypedAstBuilder {
15381538
})
15391539
.collect();
15401540

1541-
// Use Unknown type for now - proper struct types would need TypeRegistry lookup
1542-
let struct_type = Type::Unknown;
1541+
// Create an inline struct type with the fields from the literal
1542+
// This allows field access to work without a TypeRegistry lookup
1543+
let struct_fields: Vec<zyntax_typed_ast::type_registry::FieldDef> = fields.iter()
1544+
.map(|(field_name, _h)| {
1545+
zyntax_typed_ast::type_registry::FieldDef {
1546+
name: InternedString::new_global(field_name),
1547+
ty: Type::Primitive(PrimitiveType::I32), // Default to i32 for now
1548+
visibility: Visibility::Public,
1549+
mutability: Mutability::Immutable,
1550+
is_static: false,
1551+
span,
1552+
getter: None,
1553+
setter: None,
1554+
is_synthetic: false,
1555+
}
1556+
})
1557+
.collect();
1558+
1559+
let struct_type = Type::Struct {
1560+
fields: struct_fields,
1561+
is_anonymous: false,
1562+
nullability: zyntax_typed_ast::NullabilityKind::NonNull,
1563+
};
15431564

15441565
let expr = self.inner.struct_literal(name, field_exprs, struct_type, span);
15451566
self.store_expr(expr)

0 commit comments

Comments
 (0)