unify catch fallback value sources
This commit is contained in:
@@ -6097,6 +6097,72 @@ main func() i32 {
|
||||
testing.expect_value(t, state.exit_code, 0)
|
||||
}
|
||||
|
||||
@(test)
|
||||
catch_fallback_value_sources_compile_and_run :: proc(t: ^testing.T) {
|
||||
text := `Failure :: enum {
|
||||
bad
|
||||
worse
|
||||
}
|
||||
value func(fail bool, worse bool) i32 ! Failure {
|
||||
if fail {
|
||||
if worse { return .worse }
|
||||
return .bad
|
||||
}
|
||||
return 10
|
||||
}
|
||||
void_value func(fail bool) void ! Failure {
|
||||
if fail { return .bad }
|
||||
}
|
||||
capture_score func(err Failure) i32 {
|
||||
return match err {
|
||||
.bad: 1
|
||||
.worse: 2
|
||||
}
|
||||
}
|
||||
consume func(err Failure) void { _ = err }
|
||||
comptime_recovery func() i32 {
|
||||
return value(true, false) catch |err| capture_score(err)
|
||||
}
|
||||
main func() i32 {
|
||||
a :: value(true, false) catch 3
|
||||
b :: value(true, false) catch |err| capture_score(err)
|
||||
c :: value(true, true) catch |err| match err {
|
||||
.bad: 4
|
||||
.worse: 5
|
||||
}
|
||||
d :: value(true, false) catch if true {
|
||||
yield 6
|
||||
} else {
|
||||
yield 7
|
||||
}
|
||||
e :: value(true, false) catch {
|
||||
yield 8
|
||||
}
|
||||
f :: value(true, false) catch |err| {
|
||||
_ = err
|
||||
yield 9
|
||||
}
|
||||
g :: value(false, false) catch unreachable
|
||||
h :: value(false, false) catch |_| unreachable
|
||||
void_value(true) catch |err| consume(err)
|
||||
void_value(false) catch {}
|
||||
ct i32 :: $comptime_recovery()
|
||||
return a + b + c + d + e + f + g + h + ct - 53
|
||||
}
|
||||
`
|
||||
directory := "/tmp/brolang-test-catch-value-sources"
|
||||
main_path := "/tmp/brolang-test-catch-value-sources/main.bro"
|
||||
output := "/tmp/brolang-test-catch-value-sources-output"
|
||||
_ = os2.remove_all(directory)
|
||||
defer _ = os2.remove_all(directory)
|
||||
defer _ = os.remove(output)
|
||||
testing.expect(t, os.make_directory(directory) == nil)
|
||||
testing.expect(t, os.write_entire_file(main_path, transmute([]byte)text))
|
||||
testing.expect_value(t, compiler_core.compile_package(directory, output), 0)
|
||||
state := run_executable(output)
|
||||
testing.expect_value(t, state.exit_code, 0)
|
||||
}
|
||||
|
||||
@(test)
|
||||
fallible_void_fallthrough_compiles_at_runtime_and_comptime :: proc(t: ^testing.T) {
|
||||
text := `Failure :: enum {
|
||||
|
||||
Reference in New Issue
Block a user