bug fixes
This commit is contained in:
+79
-35
@@ -3961,6 +3961,77 @@ main func() i32 {
|
||||
testing.expect_value(t, compiler_core.compile_package(directory, output), 1)
|
||||
}
|
||||
|
||||
@(test)
|
||||
terminating_catch_block_compiles_and_runs :: proc(t: ^testing.T) {
|
||||
text := `Failure :: enum {
|
||||
bad
|
||||
}
|
||||
may_fail func(fail bool) i32 ! Failure {
|
||||
if (fail) return .bad
|
||||
return 1
|
||||
}
|
||||
recover func(fail bool) i32 {
|
||||
value :: may_fail(fail) catch |_| {
|
||||
return 40
|
||||
}
|
||||
return value + 1
|
||||
}
|
||||
main func() i32 {
|
||||
return recover(false) + recover(true) - 42
|
||||
}
|
||||
`
|
||||
directory := "/tmp/brolang-test-terminating-catch"
|
||||
main_path := "/tmp/brolang-test-terminating-catch/main.bro"
|
||||
output := "/tmp/brolang-test-terminating-catch-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 {
|
||||
marker i32
|
||||
}
|
||||
take func(allocator Allocator, memory []mut u8) void {}
|
||||
main func() void {
|
||||
allocator Allocator = Allocator { marker = 0 }
|
||||
data [1]mut u8 = [0]
|
||||
take(data[..], allocator)
|
||||
}
|
||||
`
|
||||
source_file := source.Source{path="type_labels.bro", text=text}
|
||||
diagnostics := source.init_diagnostics(&source_file)
|
||||
defer source.destroy_diagnostics(&diagnostics)
|
||||
symbols := symbol.init_table()
|
||||
defer symbol.destroy_table(&symbols)
|
||||
stream := lexer.lex(&source_file, &diagnostics, &symbols)
|
||||
defer delete(stream.items)
|
||||
ast_module := parser.parse(&stream, &source_file, &diagnostics)
|
||||
defer ast.destroy_module(&ast_module)
|
||||
hir_module := checker.check(&ast_module, &diagnostics, &symbols)
|
||||
defer hir.destroy_module(&hir_module)
|
||||
|
||||
slice_to_allocator := false
|
||||
allocator_to_slice := false
|
||||
internal_type_id := false
|
||||
for diagnostic in diagnostics.items {
|
||||
slice_to_allocator = slice_to_allocator ||
|
||||
strings.contains(diagnostic.message, "cannot implicitly convert []mut u8 to Allocator")
|
||||
allocator_to_slice = allocator_to_slice ||
|
||||
strings.contains(diagnostic.message, "cannot implicitly convert Allocator to []mut u8")
|
||||
internal_type_id = internal_type_id || strings.contains(diagnostic.message, "<type ")
|
||||
}
|
||||
testing.expect(t, slice_to_allocator)
|
||||
testing.expect(t, allocator_to_slice)
|
||||
testing.expect(t, !internal_type_id)
|
||||
}
|
||||
|
||||
@(test)
|
||||
contextual_payload_variants_compile :: proc(t: ^testing.T) {
|
||||
text := `DetailError :: union(enum) {
|
||||
@@ -4941,26 +5012,6 @@ folded_constant_addition_compiles_and_runs :: proc(t: ^testing.T) {
|
||||
testing.expect_value(t, state.exit_code, 0)
|
||||
}
|
||||
|
||||
@(test)
|
||||
unused_invalid_global_does_not_trap :: proc(t: ^testing.T) {
|
||||
output := "/tmp/brolang-test-invalid-unused"
|
||||
defer _ = os.remove(output)
|
||||
status := compiler_core.compile_package("examples/programs/invalid_unused_global", output)
|
||||
testing.expect_value(t, status, 1)
|
||||
state := run_executable(output)
|
||||
testing.expect_value(t, state.exit_code, 0)
|
||||
}
|
||||
|
||||
@(test)
|
||||
used_invalid_global_traps :: proc(t: ^testing.T) {
|
||||
output := "/tmp/brolang-test-invalid-used"
|
||||
defer _ = os.remove(output)
|
||||
status := compiler_core.compile_package("examples/programs/invalid_used_global", output)
|
||||
testing.expect_value(t, status, 1)
|
||||
state := run_executable(output)
|
||||
testing.expect(t, !state.success)
|
||||
}
|
||||
|
||||
@(test)
|
||||
main_int_is_constrained_to_i32 :: proc(t: ^testing.T) {
|
||||
output := "/tmp/brolang-test-main-int"
|
||||
@@ -4981,16 +5032,6 @@ main_i32_returns_directly :: proc(t: ^testing.T) {
|
||||
testing.expect_value(t, state.exit_code, 4)
|
||||
}
|
||||
|
||||
@(test)
|
||||
transitive_problematic_global_is_deferred :: proc(t: ^testing.T) {
|
||||
output := "/tmp/brolang-test-transitive-unused"
|
||||
defer _ = os.remove(output)
|
||||
status := compiler_core.compile_package("examples/programs/invalid_transitive_unused_global", output)
|
||||
testing.expect_value(t, status, 1)
|
||||
state := run_executable(output)
|
||||
testing.expect_value(t, state.exit_code, 0)
|
||||
}
|
||||
|
||||
@(test)
|
||||
checked_addition_traps_on_overflow :: proc(t: ^testing.T) {
|
||||
output := "/tmp/brolang-test-overflow"
|
||||
@@ -6159,13 +6200,16 @@ main func() void {}
|
||||
hir_module := checker.check(&ast_module, &diagnostics, &symbols)
|
||||
defer hir.destroy_module(&hir_module)
|
||||
|
||||
found_signed_range := 0
|
||||
found_expression_range := 0
|
||||
found_literal_range := 0
|
||||
found_u64_range := false
|
||||
for diagnostic in diagnostics.items {
|
||||
found_signed_range += 1 if strings.contains(diagnostic.message, "exceeds signed i64 range") else 0
|
||||
found_expression_range += 1 if strings.contains(diagnostic.message, "exceeds signed i64 range") else 0
|
||||
found_literal_range += 1 if strings.contains(diagnostic.message, "does not fit in i64") else 0
|
||||
found_u64_range = found_u64_range || strings.contains(diagnostic.message, "magnitude does not fit in u64")
|
||||
}
|
||||
testing.expect_value(t, found_signed_range, 4)
|
||||
testing.expect_value(t, found_expression_range, 2)
|
||||
testing.expect_value(t, found_literal_range, 2)
|
||||
testing.expect(t, found_u64_range)
|
||||
}
|
||||
|
||||
@@ -6479,7 +6523,7 @@ main func() void {
|
||||
for global in hir_module.globals {
|
||||
name := symbol.resolve(&symbols, global.name)
|
||||
if name == "counter" {
|
||||
found_counter = global.writable && !global.is_static && types.equal(global.type, types.I8)
|
||||
found_counter = global.writable && !global.is_static && types.equal(global.type, types.I32)
|
||||
} else if name == "ratio" {
|
||||
found_ratio = global.writable && !global.is_static && types.equal(global.type, types.F64)
|
||||
} else if name == "span" {
|
||||
@@ -6494,7 +6538,7 @@ main func() void {
|
||||
testing.expect(t, found_span)
|
||||
testing.expect(t, found_values)
|
||||
testing.expect(t, strings.contains(llvm_text, "internal global"))
|
||||
testing.expect(t, !strings.contains(llvm_text, "internal constant i8 0"))
|
||||
testing.expect(t, !strings.contains(llvm_text, "internal constant i32 0"))
|
||||
}
|
||||
|
||||
@(test)
|
||||
|
||||
Reference in New Issue
Block a user