report global cycle endpoints

This commit is contained in:
2026-06-30 22:20:35 +02:00
parent 5161e99af5
commit eb06b2ee62
3 changed files with 64 additions and 12 deletions
+27
View File
@@ -4684,6 +4684,33 @@ hundred_thousand_term_runtime_addition_uses_iterative_pipeline :: proc(t: ^testi
testing.expect(t, instruction_count > 100_000)
}
@(test)
global_cycle_diagnostic_reports_endpoint_lines :: proc(t: ^testing.T) {
text := `a i32 :: b
b i32 :: a
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)
found := false
for _, diagnostic_index in diagnostics.items {
message := source.format(&diagnostics, source.diagnostic_id(diagnostic_index))
found = found || strings.contains(message, "global initialization cycle from 'a' at test.bro:1 to 'b' at test.bro:2")
delete(message)
}
testing.expect(t, found)
}
@(test)
deep_global_cycle_detection_uses_iterative_dfs :: proc(t: ^testing.T) {
count := 50_000