fix: allow multiline grouped sum types
This commit is contained in:
@@ -7680,6 +7680,65 @@ main func() i32 {
|
||||
testing.expect(t, strings.contains(llvm_text, "call void @llvm.memcpy.p0.p0.i64"))
|
||||
}
|
||||
|
||||
@(test)
|
||||
multiline_grouped_sum_types_compile_and_run :: proc(t: ^testing.T) {
|
||||
directory :: "/tmp/brolang-test-multiline-sums"
|
||||
output := "/tmp/brolang-test-multiline-sums-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.make_directory(directory + "/errors") == nil)
|
||||
errors_text := `AllocError :: enum { alloc }
|
||||
CapacityError :: enum { capacity }
|
||||
SourceError :: union(enum) { source i32 }
|
||||
`
|
||||
testing.expect(t, os.write_entire_file(directory + "/errors/errors.hon", transmute([]byte)errors_text))
|
||||
text := `errors :: import "errors"
|
||||
@hide:file
|
||||
DriverError :: alias (
|
||||
errors.AllocError
|
||||
| (
|
||||
errors.CapacityError |
|
||||
errors.SourceError
|
||||
)
|
||||
)
|
||||
code func(err DriverError) i32 {
|
||||
return match err {
|
||||
.alloc: 1
|
||||
.capacity: 2
|
||||
.source |value|: value
|
||||
}
|
||||
}
|
||||
fail func() void ! (
|
||||
errors.AllocError
|
||||
|
|
||||
errors.CapacityError
|
||||
) {
|
||||
return .capacity
|
||||
}
|
||||
main func() i32 {
|
||||
if (code(.alloc) != 1) return 1
|
||||
if (code(.capacity) != 2) return 2
|
||||
if (code(.source{42}) != 42) return 3
|
||||
result := 0
|
||||
fail() catch |err| {
|
||||
result = code(err)
|
||||
}
|
||||
if (result != 2) return 4
|
||||
return 0
|
||||
}
|
||||
`
|
||||
testing.expect(t, os.write_entire_file(directory + "/main.hon", transmute([]byte)text))
|
||||
status := compiler_core.compile_package(directory, output)
|
||||
testing.expect_value(t, status, 0)
|
||||
if status != 0 {
|
||||
return
|
||||
}
|
||||
state := run_executable(output)
|
||||
testing.expect_value(t, state.exit_code, 0)
|
||||
}
|
||||
|
||||
@(test)
|
||||
anonymous_struct_payloads_and_keyed_payload_sugar_compile :: proc(t: ^testing.T) {
|
||||
text := `PayloadError :: union(enum) {
|
||||
|
||||
Reference in New Issue
Block a user