distinct type aliasing

This commit is contained in:
2026-06-23 12:29:21 +02:00
parent 6512ccd543
commit f16f352d1e
15 changed files with 525 additions and 58 deletions
+17
View File
@@ -1477,6 +1477,19 @@ parse_struct :: proc(parser: ^Parser, name: token.Token, c_layout: bool) {
_ = finish_statement(parser)
}
parse_distinct :: proc(parser: ^Parser, name: token.Token) {
start := advance(parser)
child := parse_type(parser)
id := types.named(&parser.module.type_store, u32(parser.pkg), u32(name.symbol))
if !types.define_distinct(&parser.module.type_store, id, child) {
source.addf(parser.diagnostics, name.span, "duplicate type declaration '%s'", token_text(parser, name))
}
if !types.is_valid(child) {
source.add(parser.diagnostics, start.span, "distinct declarations require a backing type")
}
_ = finish_statement(parser)
}
decode_import_path :: proc(parser: ^Parser, tok: token.Token) -> string {
text := token_text(parser, tok)
if len(text) < 2 {
@@ -1588,6 +1601,10 @@ parse_top_level :: proc(parser: ^Parser) {
parse_struct(parser, name, current(parser).kind == .Keyword_C_Struct)
return
}
if operator.kind == .Colon_Colon && current(parser).kind == .Keyword_Distinct {
parse_distinct(parser, name)
return
}
expr := parse_expression(parser)
_ = ast.global_id(len(parser.module.globals))