tagged unions
This commit is contained in:
@@ -1048,6 +1048,25 @@ validate_type_nodes :: proc(checker: ^Checker) {
|
||||
)
|
||||
}
|
||||
}
|
||||
// A tagged union (`item.child` set) must tag with an enum, and each variant
|
||||
// must name a member of it. The synthesized `union(enum)` tag satisfies this
|
||||
// by construction; the check guards the explicit `union(Enum)` form.
|
||||
if item.kind == .Union && types.is_valid(item.child) {
|
||||
if !types.is_enum(item.child, &checker.module.types) {
|
||||
source.add(checker.diagnostics, source.Span{}, "a tagged union's tag must be an enum")
|
||||
} else {
|
||||
for field in types.fields_for(&checker.module.types, id) {
|
||||
if _, ok := find_enum_member(checker, item.child, symbol.Id(field.name)); !ok {
|
||||
source.addf(
|
||||
checker.diagnostics,
|
||||
source.Span{},
|
||||
"union variant '%s' is not a member of the tag enum",
|
||||
symbol_text(checker, symbol.Id(field.name)),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if item.kind == .Function {
|
||||
if !item.c_abi {
|
||||
|
||||
Reference in New Issue
Block a user