bug fixes

This commit is contained in:
2026-07-13 23:34:14 +02:00
parent 0eeacc2e37
commit 0b0b00a050
6 changed files with 114 additions and 17 deletions
+64 -3
View File
@@ -2585,9 +2585,8 @@ main func() i32 {
testing.expect_value(t, len(diagnostics.items), 0)
testing.expect_value(t, len(hir_module.functions), 3)
for global in hir_module.globals {
testing.expect(t, types.equal(global.type, types.I8))
}
testing.expect(t, types.equal(hir_module.globals[0].type, types.I32))
testing.expect(t, types.equal(hir_module.globals[1].type, types.I8))
}
@(test)
@@ -4249,6 +4248,50 @@ main func() i32 {
testing.expect_value(t, state.exit_code, 0)
}
@(test)
fallible_void_fallthrough_compiles_at_runtime_and_comptime :: proc(t: ^testing.T) {
text := `Failure :: enum {
bad
}
succeed func() void ! Failure {}
fail func() void ! Failure { return .bad }
maybe func(should_fail bool) void ! Failure {
if should_fail { return .bad }
}
recover func(exit bool) i32 {
fail() catch |_| {
if exit { return 7 }
}
return 0
}
comptime_scenario func() i32 {
succeed() catch |_| {}
fail() catch |_| {}
return 0
}
main func() i32 {
comptime_result i32 :: $comptime_scenario()
handled bool = false
fail() catch |_| { handled = true }
if !handled { return 3 }
succeed() catch |_| { return 1 }
maybe(false) catch |_| { return 2 }
return comptime_result + recover(false) + recover(true) - 7
}
`
directory := "/tmp/brolang-test-fallible-void-fallthrough"
main_path := "/tmp/brolang-test-fallible-void-fallthrough/main.bro"
output := "/tmp/brolang-test-fallible-void-fallthrough-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)
conversion_diagnostics_render_source_types :: proc(t: ^testing.T) {
text := `Allocator :: struct {
@@ -6739,6 +6782,24 @@ valid_runtime_global_initializes_before_main :: proc(t: ^testing.T) {
testing.expect_value(t, state.exit_code, 0)
}
@(test)
inferred_string_global_decays_to_demanded_slice :: proc(t: ^testing.T) {
text := "consume func(value []u8) usize { return value.len }\n" +
"program ::\n\t`abc\n" +
"main func() i32 {\n\tif consume(program) == 3 { return 0 }\n\treturn 1\n}\n"
directory := "/tmp/brolang-test-inferred-string-global"
main_path := "/tmp/brolang-test-inferred-string-global/main.bro"
output := "/tmp/brolang-test-inferred-string-global-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)
mutable_runtime_globals_compile_and_run :: proc(t: ^testing.T) {
output := "/tmp/brolang-test-mutable-global"