fix(checker): infer return match calls
This commit is contained in:
@@ -6367,6 +6367,41 @@ main func() i32 {
|
||||
testing.expect(t, len(hir_module.functions) > 1)
|
||||
}
|
||||
|
||||
@(test)
|
||||
return_match_inference_visits_arm_calls :: proc(t: ^testing.T) {
|
||||
text := `Kind :: enum {
|
||||
a
|
||||
b
|
||||
}
|
||||
identity func(value i32) i32 {
|
||||
return value
|
||||
}
|
||||
choose func(kind Kind) i32 {
|
||||
return match kind {
|
||||
.a: identity(41)
|
||||
.b: identity(42)
|
||||
}
|
||||
}
|
||||
main func() i32 {
|
||||
return choose(.a) - 41
|
||||
}
|
||||
`
|
||||
source_file := source.Source{path="return_match_call.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)
|
||||
testing.expect(t, len(hir_module.functions) > 2)
|
||||
}
|
||||
|
||||
@(test)
|
||||
fallible_ergonomics_rejects_bad_try_and_catch_blocks :: proc(t: ^testing.T) {
|
||||
text := `A :: enum {
|
||||
|
||||
Reference in New Issue
Block a user