enforce leading comptime params

This commit is contained in:
2026-07-12 19:48:36 +02:00
parent 2dea7711f2
commit c914083102
4 changed files with 52 additions and 0 deletions
+36
View File
@@ -2650,6 +2650,42 @@ main func() void {
testing.expect(t, unrecoverable >= 3)
}
@(test)
comptime_params_must_form_leading_prefix :: proc(t: ^testing.T) {
text := `valid func($T type, $N usize, value T) [N]T {
result [N]T = undefined
_ = value
return result
}
runtime_first func(value i32, $T type, $N usize) T { return value }
split func($T type, value T, $N usize) [N]T {
result [N]T = undefined
_ = value
return result
}
main func() void {}
`
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)
count := 0
for diagnostic in diagnostics.items {
if strings.contains(diagnostic.message, "comptime parameters must form a leading parameter prefix") {
count += 1
}
}
testing.expect_value(t, count, 2)
}
@(test)
comptime_type_params_specialize_by_type_and_omit_runtime_args :: proc(t: ^testing.T) {
text := `Point :: struct {