structs as errors in fallibles
This commit is contained in:
@@ -6953,6 +6953,51 @@ main func() i32 {
|
||||
testing.expect_value(t, state.exit_code, 0)
|
||||
}
|
||||
|
||||
@(test)
|
||||
struct_error_channels_compile_and_run_at_runtime_and_comptime :: proc(t: ^testing.T) {
|
||||
text := `ScanError :: struct {
|
||||
code i32
|
||||
start usize
|
||||
end usize
|
||||
}
|
||||
scan func(fail bool) i32 ! ScanError {
|
||||
if fail {
|
||||
return ScanError { code = 5, start = 7, end = 11 }
|
||||
}
|
||||
return 41
|
||||
}
|
||||
scan_local func() i32 ! ScanError {
|
||||
err ScanError := ScanError { code = 3, start = 13, end = 17 }
|
||||
return err
|
||||
}
|
||||
forward func(fail bool) i32 ! ScanError {
|
||||
return try scan(fail)
|
||||
}
|
||||
score_comptime func() i32 {
|
||||
return scan(true) catch |err| err.code + i32(err.start) + i32(err.end)
|
||||
}
|
||||
main func() i32 {
|
||||
direct :: scan(true) catch |err| err.code + i32(err.start) + i32(err.end)
|
||||
local :: scan_local() catch |err| err.code + i32(err.start) + i32(err.end)
|
||||
forwarded :: forward(true) catch |err| err.code + i32(err.start) + i32(err.end)
|
||||
success :: forward(false) catch 0
|
||||
comptime_score i32 :: $score_comptime()
|
||||
return direct + local + forwarded + success + comptime_score - 143
|
||||
}
|
||||
`
|
||||
directory := "/tmp/brolang-test-struct-error-channel"
|
||||
main_path := "/tmp/brolang-test-struct-error-channel/main.bro"
|
||||
output := "/tmp/brolang-test-struct-error-channel-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)
|
||||
matched_error_residuals_return_at_runtime_and_comptime :: proc(t: ^testing.T) {
|
||||
text := `KeyError :: enum { key_exists }
|
||||
|
||||
Reference in New Issue
Block a user