comptime-state propagation through generated struct field resolution

This commit is contained in:
2026-07-20 08:33:59 +02:00
parent 59bbb197e0
commit 10abba54a5
3 changed files with 49 additions and 24 deletions
+21 -8
View File
@@ -13819,17 +13819,29 @@ Generated func($T type) type {
GeneratedInt :: alias Generated(i32)
ordered Names = {}
Map func($E, $V type) type { return struct { count usize } }
init func($E, $V type, values meta.EnumFieldStruct(E, ?V, some!(none))) Map(E, V) {
count usize = 0
Map func($E, $V type) type {
match typeinfo!(E) {
.enum |info|: expand for info.fields |field| {
if field!(values, field.name) |_| { count += 1 }
.enum |info|: return struct {
present [info.fields.len]mut bool
values [info.fields.len]mut V
}
else: compile_error!("EnumMap key must be an enum")
}
return Map(E, V) {count = count}
}
init func($E, $V type, values meta.EnumFieldStruct(E, ?V, some!(none))) Map(E, V) {
map Map(E, V) = undefined
match typeinfo!(E) {
.enum |info|: expand for info.fields |field, index| {
map.present[index] = false
if field!(values, field.name) |value| {
map.present[index] = true
map.values[index] = value
}
}
else: compile_error!("EnumMap key must be an enum")
}
return map
}
main func() i32 {
@@ -13875,7 +13887,8 @@ main func() i32 {
ident = "identifier",
int = "integer",
})
if map.count != 2 { return 9 }
if !map.present[0] or !map.present[1] or map.present[2] { return 9 }
if map.values[0].len != 10 or map.values[1].len != 7 { return 18 }
return 0
}
`