close some gaps in the type system
This commit is contained in:
+98
-10
@@ -5812,7 +5812,7 @@ main func() i32 {
|
||||
testing.expect(t, found_yield)
|
||||
testing.expect(t, found_misplaced_yield)
|
||||
|
||||
success_text := `A :: enum {
|
||||
local_success_text := `A :: enum {
|
||||
a
|
||||
}
|
||||
B :: enum {
|
||||
@@ -5822,23 +5822,26 @@ Both :: alias A | B
|
||||
fs func() i64 ! A {
|
||||
return 1
|
||||
}
|
||||
bad_success func() i32 ! Both {
|
||||
use_success func() void ! Both {
|
||||
x :: try fs()
|
||||
return x
|
||||
_ = x
|
||||
}
|
||||
main func() i32 {
|
||||
return bad_success() catch 0
|
||||
use_success() catch |_| { return 1 }
|
||||
return 0
|
||||
}
|
||||
`
|
||||
directory := "/tmp/brolang-test-try-success-mismatch"
|
||||
main_path := "/tmp/brolang-test-try-success-mismatch/main.bro"
|
||||
output := "/tmp/brolang-test-try-success-mismatch-output"
|
||||
directory := "/tmp/brolang-test-try-local-success"
|
||||
main_path := "/tmp/brolang-test-try-local-success/main.bro"
|
||||
output := "/tmp/brolang-test-try-local-success-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)success_text))
|
||||
testing.expect_value(t, compiler_core.compile_package(directory, output), 1)
|
||||
testing.expect(t, os.write_entire_file(main_path, transmute([]byte)local_success_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)
|
||||
@@ -6032,7 +6035,10 @@ OtherError :: union(enum) {
|
||||
}
|
||||
other void
|
||||
}
|
||||
BothError :: alias PayloadError | OtherError
|
||||
BothError :: alias (PayloadError | OtherError)
|
||||
grouped_error func() void ! (PayloadError | OtherError) {
|
||||
return .other
|
||||
}
|
||||
accept func(value PayloadError) i32 {
|
||||
match value {
|
||||
.not_found |info|: return info.path + info.line
|
||||
@@ -13609,6 +13615,10 @@ milestone_44_struct_field_defaults_compile_and_run :: proc(t: ^testing.T) {
|
||||
|
||||
Lists :: struct { items [][]u8 = &[] }
|
||||
|
||||
Generated func($T type, $initial i32) type {
|
||||
return struct { value T = initial }
|
||||
}
|
||||
|
||||
read func(value Config) i32 {
|
||||
return value.required + value.count
|
||||
}
|
||||
@@ -13619,10 +13629,12 @@ main func() i32 {
|
||||
defaults Config = Config{required = 35}
|
||||
overridden Config = Config{count = 1, enabled = false, name = "x", required = 40}
|
||||
lists Lists = Lists{}
|
||||
generated Generated(i32, 9) = Generated(i32, 9){}
|
||||
if (ANSWER != 42) return 1
|
||||
if (defaults.count != 7 or defaults.enabled == false) return 2
|
||||
if (defaults.name.len != 3 or lists.items.len != 0) return 3
|
||||
if (overridden.count != 1 or overridden.enabled or overridden.name.len != 1) return 4
|
||||
if (generated.value != 9) return 5
|
||||
return 0
|
||||
}
|
||||
`
|
||||
@@ -13635,3 +13647,79 @@ main func() i32 {
|
||||
state := run_executable(output)
|
||||
testing.expect_value(t, state.exit_code, 0)
|
||||
}
|
||||
|
||||
@(test)
|
||||
dependent_comptime_callbacks_and_imported_grouped_sums_compile :: proc(t: ^testing.T) {
|
||||
directory := "/tmp/brolang-test-dependent-callbacks"
|
||||
app := "/tmp/brolang-test-dependent-callbacks/app"
|
||||
dependency := "/tmp/brolang-test-dependent-callbacks/dependency"
|
||||
app_path := "/tmp/brolang-test-dependent-callbacks/app/main.bro"
|
||||
dependency_path := "/tmp/brolang-test-dependent-callbacks/dependency/errors.bro"
|
||||
output := "/tmp/brolang-test-dependent-callbacks-output"
|
||||
_ = os2.remove_all(directory)
|
||||
defer _ = os2.remove_all(directory)
|
||||
defer _ = os.remove(output)
|
||||
testing.expect(t, os2.make_directory_all(app) == nil)
|
||||
testing.expect(t, os2.make_directory_all(dependency) == nil)
|
||||
|
||||
dependency_text := `AllocError :: enum { out_of_memory }
|
||||
`
|
||||
app_text := `dependency :: import "../dependency"
|
||||
|
||||
PutError :: enum { key_exists }
|
||||
|
||||
Entry func($K, $V type) type {
|
||||
return struct { key K, value V }
|
||||
}
|
||||
|
||||
Map func(
|
||||
$K, $V type,
|
||||
$hash_key func(key K) usize,
|
||||
$keys_eql func(a, b K) bool,
|
||||
) type {
|
||||
return struct { entry Entry(K, V) }
|
||||
}
|
||||
|
||||
hash func(key []u8) usize { return key.len }
|
||||
eql func(a, b []u8) bool { return a.len == b.len }
|
||||
|
||||
StringMap func($V type) type {
|
||||
return Map([]u8, V, hash, eql)
|
||||
}
|
||||
|
||||
make func(
|
||||
$K, $V type,
|
||||
$hash_key func(key K) usize,
|
||||
$keys_eql func(a, b K) bool,
|
||||
) Map(K, V, hash_key, keys_eql) {
|
||||
return Map(K, V, hash_key, keys_eql) {
|
||||
entry = Entry(K, V) {key = "", value = 0},
|
||||
}
|
||||
}
|
||||
|
||||
put func(
|
||||
$K, $V type,
|
||||
$hash_key func(key K) usize,
|
||||
$keys_eql func(a, b K) bool,
|
||||
map @Map(K, V, hash_key, keys_eql),
|
||||
key K,
|
||||
) void {
|
||||
_ = map
|
||||
_ = key
|
||||
}
|
||||
|
||||
fallible func() void ! (PutError | dependency.AllocError) { return .key_exists }
|
||||
|
||||
main func() void {
|
||||
map StringMap(u32) = make()
|
||||
put(&map, "key")
|
||||
_ = map
|
||||
fallible() catch |_| {}
|
||||
}
|
||||
`
|
||||
testing.expect(t, os.write_entire_file(dependency_path, transmute([]byte)dependency_text))
|
||||
testing.expect(t, os.write_entire_file(app_path, transmute([]byte)app_text))
|
||||
testing.expect_value(t, compiler_core.compile_package(app, output), 0)
|
||||
state := run_executable(output)
|
||||
testing.expect_value(t, state.exit_code, 0)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user