better comptime match-statement support

This commit is contained in:
2026-07-16 08:57:54 +02:00
parent 3cc750b3b2
commit 1f25e6cd1d
4 changed files with 159 additions and 119 deletions
+47
View File
@@ -2818,6 +2818,53 @@ main func() void {
testing.expect_value(t, len(diagnostics.items), 0)
}
@(test)
milestone_37_inline_match_specialization_prunes_unselected_arms :: proc(t: ^testing.T) {
text := `Kind :: enum { integer, string, stop }
IntToken :: struct { kind Kind, value i8 }
StringToken :: struct { kind Kind, value []u8 }
StopToken :: struct { kind Kind, value bool }
take_i8 func(value i8) void { _ = value }
main func() void {
inline for {
IntToken {kind = .integer, value = 1},
StringToken {kind = .string, value = "ok"},
StopToken {kind = .stop, value = false},
} |token| {
match token.kind {
.integer: take_i8(token.value)
.string: {
_ = token.value.len
continue
}
.stop: break
}
}
inline for {i8(2), "skip", "stop"} |value, index| {
match index {
0: {}
1..=1, 7: continue
else: break
}
take_i8(value)
}
}
`
source_file := source.Source{path="test.bro", text=text}
diagnostics := source.init_diagnostics(&source_file)
defer source.destroy_diagnostics(&diagnostics)
symbols := symbol.init_table()
defer symbol.destroy_table(&symbols)
stream := lexer.lex(&source_file, &diagnostics, &symbols)
defer delete(stream.items)
ast_module := parser.parse(&stream, &source_file, &diagnostics)
defer ast.destroy_module(&ast_module)
hir_module := checker.check(&ast_module, &diagnostics, &symbols)
defer hir.destroy_module(&hir_module)
testing.expect_value(t, len(diagnostics.items), 0)
}
@(test)
milestone_33_rejects_an_incompatible_runtime_write_declaration :: proc(t: ^testing.T) {
text := `write c_func(_ c_int, _ c_int, _ c_ulong) c_long