From 97b781955eca7c3fc6ee2713f8b5e355645fff58 Mon Sep 17 00:00:00 2001 From: Jakub Konka Date: Wed, 27 Apr 2022 15:37:54 +0200 Subject: [PATCH] test: fix incorrect default target spec; port all incremental tests --- src/test.zig | 2 +- ..._slice_element_by_index_slice_elem_val.zig | 17 +++++++++ test/incremental/ambiguous_reference.zig | 13 +++++++ .../bad_inferred_variable_type.zig | 9 +++++ test/incremental/break_continue.0.zig | 9 +++++ test/incremental/break_continue.1.zig | 8 +++++ test/incremental/break_continue.2.zig | 10 ++++++ test/incremental/break_continue.3.zig | 10 ++++++ test/incremental/catch_at_comptime.0.zig | 11 ++++++ test/incremental/catch_at_comptime.1.zig | 11 ++++++ test/incremental/catch_at_comptime.2.zig | 11 ++++++ test/incremental/catch_at_comptime.3.zig | 10 ++++++ test/incremental/catch_at_comptime.4.zig | 10 ++++++ test/incremental/compile_error.zig | 7 ++++ ...ompile_error_in_inline_fn_call_fixed.0.zig | 16 +++++++++ ...ompile_error_in_inline_fn_call_fixed.1.zig | 13 +++++++ test/incremental/compile_log.0.zig | 17 +++++++++ test/incremental/compile_log.1.zig | 16 +++++++++ test/incremental/comptime_var.0.zig | 12 +++++++ test/incremental/comptime_var.1.zig | 13 +++++++ test/incremental/comptime_var.2.zig | 34 ++++++++++++++++++ test/incremental/comptime_var.3.zig | 10 ++++++ test/incremental/comptime_var.4.zig | 9 +++++ test/incremental/comptime_var.5.zig | 15 ++++++++ test/incremental/comptime_var.6.zig | 32 +++++++++++++++++ test/incremental/double_ampersand.0.zig | 6 ++++ test/incremental/double_ampersand.1.zig | 11 ++++++ test/incremental/double_ampersand.2.zig | 7 ++++ .../extern_variable_has_no_type.0.zig | 9 +++++ .../extern_variable_has_no_type.1.zig | 8 +++++ test/incremental/function_redeclaration.zig | 14 ++++++++ .../global_variable_redeclaration.zig | 8 +++++ ...ello_world_with_updates_x86_64_linux.0.zig | 5 +++ ...ello_world_with_updates_x86_64_linux.1.zig | 5 +++ ...ello_world_with_updates_x86_64_linux.2.zig | 32 +++++++++++++++++ ...ello_world_with_updates_x86_64_linux.3.zig | 20 +++++++++++ ...ello_world_with_updates_x86_64_linux.4.zig | 20 +++++++++++ ...ello_world_with_updates_x86_64_linux.5.zig | 22 ++++++++++++ ...ello_world_with_updates_x86_64_macos.0.zig | 5 +++ ...ello_world_with_updates_x86_64_macos.1.zig | 5 +++ ...ello_world_with_updates_x86_64_macos.2.zig | 19 ++++++++++ ...ello_world_with_updates_x86_64_macos.3.zig | 16 +++++++++ ...ello_world_with_updates_x86_64_macos.4.zig | 22 ++++++++++++ ...ello_world_with_updates_x86_64_macos.5.zig | 16 +++++++++ ...ello_world_with_updates_x86_64_macos.6.zig | 18 ++++++++++ .../inline_assembly_x86_64_linux.0.zig | 16 +++++++++ .../inline_assembly_x86_64_linux.1.zig | 15 ++++++++ .../inline_assembly_x86_64_linux.2.zig | 12 +++++++ .../inline_assembly_x86_64_linux.3.zig | 12 +++++++ .../inner_func_accessing_outer_var.zig | 15 ++++++++ test/incremental/int_to_ptr.0.zig | 8 +++++ test/incremental/int_to_ptr.1.zig | 7 ++++ ...ee_preserved_regs_working_x86_64_linux.zig | 31 ++++++++++++++++ ...7_miscompilation_with_bool_return_type.zig | 18 ++++++++++ .../load_store_via_pointer_deref.0.zig | 16 +++++++++ .../load_store_via_pointer_deref.1.zig | 16 +++++++++ .../load_store_via_pointer_deref.2.zig | 16 +++++++++ .../lower_unnamed_consts_structs.0.zig | 25 +++++++++++++ .../lower_unnamed_consts_structs.1.zig | 35 +++++++++++++++++++ .../lower_unnamed_consts_structs.2.zig | 25 +++++++++++++ test/incremental/merge_error_sets.0.zig | 18 ++++++++++ test/incremental/merge_error_sets.1.zig | 9 +++++ ...ion_and_it_gets_updated_x86_64_linux.0.zig | 13 +++++++ ...ion_and_it_gets_updated_x86_64_linux.1.zig | 12 +++++++ test/incremental/optional_payload.0.zig | 19 ++++++++++ test/incremental/optional_payload.1.zig | 17 +++++++++ test/incremental/optional_payload.2.zig | 18 ++++++++++ test/incremental/optional_payload.3.zig | 18 ++++++++++ test/incremental/orelse_at_comptime.0.zig | 11 ++++++ test/incremental/orelse_at_comptime.1.zig | 11 ++++++ test/incremental/passing_u0_to_function.zig | 9 +++++ .../recursive_inline_function.0.zig | 12 +++++++ .../recursive_inline_function.1.zig | 16 +++++++++ test/incremental/redundant_comptime.0.zig | 7 ++++ test/incremental/redundant_comptime.1.zig | 9 +++++ test/incremental/returns_in_try.zig | 16 +++++++++ test/incremental/runtime_bitwise_and.zig | 16 +++++++++ test/incremental/runtime_bitwise_or.zig | 16 +++++++++ ..._vars_of_different_abi_size_to_stack.0.zig | 16 +++++++++ ..._vars_of_different_abi_size_to_stack.1.zig | 16 +++++++++ ..._vars_of_different_abi_size_to_stack.2.zig | 16 +++++++++ ...g_an_address_space_on_a_local_variable.zig | 8 +++++ .../try_in_comptime_in_struct_in_test.zig | 13 +++++++ test/incremental/type_of.0.zig | 13 +++++++ test/incremental/type_of.1.zig | 11 ++++++ test/incremental/type_of.2.zig | 9 +++++ test/incremental/unused_labels.0.zig | 8 +++++ test/incremental/unused_labels.1.zig | 7 ++++ test/incremental/unused_labels.2.zig | 7 ++++ test/incremental/unused_labels.3.zig | 8 +++++ .../unwrap_error_union_simple_errors.0.zig | 10 ++++++ .../unwrap_error_union_simple_errors.1.zig | 11 ++++++ test/incremental/variable_shadowing.0.zig | 9 +++++ test/incremental/variable_shadowing.1.zig | 9 +++++ test/incremental/variable_shadowing.2.zig | 13 +++++++ test/incremental/variable_shadowing.3.zig | 10 ++++++ test/incremental/variable_shadowing.4.zig | 10 ++++++ test/incremental/variable_shadowing.5.zig | 10 ++++++ test/incremental/variable_shadowing.6.zig | 13 +++++++ test/incremental/variable_shadowing.7.zig | 9 +++++ test/incremental/variable_shadowing.8.zig | 9 +++++ test/incremental/variable_shadowing.9.zig | 9 +++++ 102 files changed, 1360 insertions(+), 1 deletion(-) create mode 100644 test/incremental/access_slice_element_by_index_slice_elem_val.zig create mode 100644 test/incremental/ambiguous_reference.zig create mode 100644 test/incremental/bad_inferred_variable_type.zig create mode 100644 test/incremental/break_continue.0.zig create mode 100644 test/incremental/break_continue.1.zig create mode 100644 test/incremental/break_continue.2.zig create mode 100644 test/incremental/break_continue.3.zig create mode 100644 test/incremental/catch_at_comptime.0.zig create mode 100644 test/incremental/catch_at_comptime.1.zig create mode 100644 test/incremental/catch_at_comptime.2.zig create mode 100644 test/incremental/catch_at_comptime.3.zig create mode 100644 test/incremental/catch_at_comptime.4.zig create mode 100644 test/incremental/compile_error.zig create mode 100644 test/incremental/compile_error_in_inline_fn_call_fixed.0.zig create mode 100644 test/incremental/compile_error_in_inline_fn_call_fixed.1.zig create mode 100644 test/incremental/compile_log.0.zig create mode 100644 test/incremental/compile_log.1.zig create mode 100644 test/incremental/comptime_var.0.zig create mode 100644 test/incremental/comptime_var.1.zig create mode 100644 test/incremental/comptime_var.2.zig create mode 100644 test/incremental/comptime_var.3.zig create mode 100644 test/incremental/comptime_var.4.zig create mode 100644 test/incremental/comptime_var.5.zig create mode 100644 test/incremental/comptime_var.6.zig create mode 100644 test/incremental/double_ampersand.0.zig create mode 100644 test/incremental/double_ampersand.1.zig create mode 100644 test/incremental/double_ampersand.2.zig create mode 100644 test/incremental/extern_variable_has_no_type.0.zig create mode 100644 test/incremental/extern_variable_has_no_type.1.zig create mode 100644 test/incremental/function_redeclaration.zig create mode 100644 test/incremental/global_variable_redeclaration.zig create mode 100644 test/incremental/hello_world_with_updates_x86_64_linux.0.zig create mode 100644 test/incremental/hello_world_with_updates_x86_64_linux.1.zig create mode 100644 test/incremental/hello_world_with_updates_x86_64_linux.2.zig create mode 100644 test/incremental/hello_world_with_updates_x86_64_linux.3.zig create mode 100644 test/incremental/hello_world_with_updates_x86_64_linux.4.zig create mode 100644 test/incremental/hello_world_with_updates_x86_64_linux.5.zig create mode 100644 test/incremental/hello_world_with_updates_x86_64_macos.0.zig create mode 100644 test/incremental/hello_world_with_updates_x86_64_macos.1.zig create mode 100644 test/incremental/hello_world_with_updates_x86_64_macos.2.zig create mode 100644 test/incremental/hello_world_with_updates_x86_64_macos.3.zig create mode 100644 test/incremental/hello_world_with_updates_x86_64_macos.4.zig create mode 100644 test/incremental/hello_world_with_updates_x86_64_macos.5.zig create mode 100644 test/incremental/hello_world_with_updates_x86_64_macos.6.zig create mode 100644 test/incremental/inline_assembly_x86_64_linux.0.zig create mode 100644 test/incremental/inline_assembly_x86_64_linux.1.zig create mode 100644 test/incremental/inline_assembly_x86_64_linux.2.zig create mode 100644 test/incremental/inline_assembly_x86_64_linux.3.zig create mode 100644 test/incremental/inner_func_accessing_outer_var.zig create mode 100644 test/incremental/int_to_ptr.0.zig create mode 100644 test/incremental/int_to_ptr.1.zig create mode 100644 test/incremental/issue_10138_callee_preserved_regs_working_x86_64_linux.zig create mode 100644 test/incremental/issue_7187_miscompilation_with_bool_return_type.zig create mode 100644 test/incremental/load_store_via_pointer_deref.0.zig create mode 100644 test/incremental/load_store_via_pointer_deref.1.zig create mode 100644 test/incremental/load_store_via_pointer_deref.2.zig create mode 100644 test/incremental/lower_unnamed_consts_structs.0.zig create mode 100644 test/incremental/lower_unnamed_consts_structs.1.zig create mode 100644 test/incremental/lower_unnamed_consts_structs.2.zig create mode 100644 test/incremental/merge_error_sets.0.zig create mode 100644 test/incremental/merge_error_sets.1.zig create mode 100644 test/incremental/only_1_function_and_it_gets_updated_x86_64_linux.0.zig create mode 100644 test/incremental/only_1_function_and_it_gets_updated_x86_64_linux.1.zig create mode 100644 test/incremental/optional_payload.0.zig create mode 100644 test/incremental/optional_payload.1.zig create mode 100644 test/incremental/optional_payload.2.zig create mode 100644 test/incremental/optional_payload.3.zig create mode 100644 test/incremental/orelse_at_comptime.0.zig create mode 100644 test/incremental/orelse_at_comptime.1.zig create mode 100644 test/incremental/passing_u0_to_function.zig create mode 100644 test/incremental/recursive_inline_function.0.zig create mode 100644 test/incremental/recursive_inline_function.1.zig create mode 100644 test/incremental/redundant_comptime.0.zig create mode 100644 test/incremental/redundant_comptime.1.zig create mode 100644 test/incremental/returns_in_try.zig create mode 100644 test/incremental/runtime_bitwise_and.zig create mode 100644 test/incremental/runtime_bitwise_or.zig create mode 100644 test/incremental/saving_vars_of_different_abi_size_to_stack.0.zig create mode 100644 test/incremental/saving_vars_of_different_abi_size_to_stack.1.zig create mode 100644 test/incremental/saving_vars_of_different_abi_size_to_stack.2.zig create mode 100644 test/incremental/setting_an_address_space_on_a_local_variable.zig create mode 100644 test/incremental/try_in_comptime_in_struct_in_test.zig create mode 100644 test/incremental/type_of.0.zig create mode 100644 test/incremental/type_of.1.zig create mode 100644 test/incremental/type_of.2.zig create mode 100644 test/incremental/unused_labels.0.zig create mode 100644 test/incremental/unused_labels.1.zig create mode 100644 test/incremental/unused_labels.2.zig create mode 100644 test/incremental/unused_labels.3.zig create mode 100644 test/incremental/unwrap_error_union_simple_errors.0.zig create mode 100644 test/incremental/unwrap_error_union_simple_errors.1.zig create mode 100644 test/incremental/variable_shadowing.0.zig create mode 100644 test/incremental/variable_shadowing.1.zig create mode 100644 test/incremental/variable_shadowing.2.zig create mode 100644 test/incremental/variable_shadowing.3.zig create mode 100644 test/incremental/variable_shadowing.4.zig create mode 100644 test/incremental/variable_shadowing.5.zig create mode 100644 test/incremental/variable_shadowing.6.zig create mode 100644 test/incremental/variable_shadowing.7.zig create mode 100644 test/incremental/variable_shadowing.8.zig create mode 100644 test/incremental/variable_shadowing.9.zig diff --git a/src/test.zig b/src/test.zig index e138afecb9..2f3389d7ff 100644 --- a/src/test.zig +++ b/src/test.zig @@ -178,7 +178,7 @@ const TestManifestConfigDefaults = struct { // getting more and more complete // Linux inline for (&[_][]const u8{ "x86_64", "arm", "aarch64" }) |arch| { - defaults = defaults ++ arch ++ "-linux-" ++ ","; + defaults = defaults ++ arch ++ "-linux" ++ ","; } // macOS inline for (&[_][]const u8{ "x86_64", "aarch64" }) |arch| { diff --git a/test/incremental/access_slice_element_by_index_slice_elem_val.zig b/test/incremental/access_slice_element_by_index_slice_elem_val.zig new file mode 100644 index 0000000000..a0bdae0826 --- /dev/null +++ b/test/incremental/access_slice_element_by_index_slice_elem_val.zig @@ -0,0 +1,17 @@ +var array = [_]usize{ 0, 42, 123, 34 }; +var slice: []const usize = &array; + +pub fn main() void { + assert(slice[0] == 0); + assert(slice[1] == 42); + assert(slice[2] == 123); + assert(slice[3] == 34); +} + +fn assert(ok: bool) void { + if (!ok) unreachable; +} + +// run +// target=x86_64-linux,x86_64-macos +// diff --git a/test/incremental/ambiguous_reference.zig b/test/incremental/ambiguous_reference.zig new file mode 100644 index 0000000000..66144a5645 --- /dev/null +++ b/test/incremental/ambiguous_reference.zig @@ -0,0 +1,13 @@ +const T = struct { + const T = struct { + fn f() void { + _ = T; + } + }; +}; + +// error +// +// :4:17: error: ambiguous reference +// :2:5: note: declared here +// :1:1: note: also declared here diff --git a/test/incremental/bad_inferred_variable_type.zig b/test/incremental/bad_inferred_variable_type.zig new file mode 100644 index 0000000000..47ceb9b638 --- /dev/null +++ b/test/incremental/bad_inferred_variable_type.zig @@ -0,0 +1,9 @@ +pub fn main() void { + var x = null; + _ = x; +} + +// error +// output_mode=Exe +// +// :2:9: error: variable of type '@TypeOf(null)' must be const or comptime diff --git a/test/incremental/break_continue.0.zig b/test/incremental/break_continue.0.zig new file mode 100644 index 0000000000..ac0abdb52d --- /dev/null +++ b/test/incremental/break_continue.0.zig @@ -0,0 +1,9 @@ +pub fn main() void { + while (true) { + break; + } +} + +// run +// target=x86_64-linux,x86_64-macos,aarch64-linux,aarch64-macos +// diff --git a/test/incremental/break_continue.1.zig b/test/incremental/break_continue.1.zig new file mode 100644 index 0000000000..9e4f79bd14 --- /dev/null +++ b/test/incremental/break_continue.1.zig @@ -0,0 +1,8 @@ +pub fn main() void { + foo: while (true) { + break :foo; + } +} + +// run +// diff --git a/test/incremental/break_continue.2.zig b/test/incremental/break_continue.2.zig new file mode 100644 index 0000000000..ba12f33e3f --- /dev/null +++ b/test/incremental/break_continue.2.zig @@ -0,0 +1,10 @@ +pub fn main() void { + var i: u64 = 0; + while (true) : (i += 1) { + if (i == 4) return; + continue; + } +} + +// run +// diff --git a/test/incremental/break_continue.3.zig b/test/incremental/break_continue.3.zig new file mode 100644 index 0000000000..03e224d265 --- /dev/null +++ b/test/incremental/break_continue.3.zig @@ -0,0 +1,10 @@ +pub fn main() void { + var i: u64 = 0; + foo: while (true) : (i += 1) { + if (i == 4) return; + continue :foo; + } +} + +// run +// diff --git a/test/incremental/catch_at_comptime.0.zig b/test/incremental/catch_at_comptime.0.zig new file mode 100644 index 0000000000..af1545832d --- /dev/null +++ b/test/incremental/catch_at_comptime.0.zig @@ -0,0 +1,11 @@ +pub fn main() void { + const i: anyerror!u64 = 0; + const caught = i catch 5; + assert(caught == 0); +} +fn assert(b: bool) void { + if (!b) unreachable; +} + +// run +// diff --git a/test/incremental/catch_at_comptime.1.zig b/test/incremental/catch_at_comptime.1.zig new file mode 100644 index 0000000000..e05caeae6d --- /dev/null +++ b/test/incremental/catch_at_comptime.1.zig @@ -0,0 +1,11 @@ +pub fn main() void { + const i: anyerror!u64 = error.B; + const caught = i catch 5; + assert(caught == 5); +} +fn assert(b: bool) void { + if (!b) unreachable; +} + +// run +// diff --git a/test/incremental/catch_at_comptime.2.zig b/test/incremental/catch_at_comptime.2.zig new file mode 100644 index 0000000000..326e6f0b61 --- /dev/null +++ b/test/incremental/catch_at_comptime.2.zig @@ -0,0 +1,11 @@ +pub fn main() void { + const a: anyerror!comptime_int = 42; + const b: *const comptime_int = &(a catch unreachable); + assert(b.* == 42); +} +fn assert(b: bool) void { + if (!b) unreachable; // assertion failure +} + +// run +// diff --git a/test/incremental/catch_at_comptime.3.zig b/test/incremental/catch_at_comptime.3.zig new file mode 100644 index 0000000000..d00317f697 --- /dev/null +++ b/test/incremental/catch_at_comptime.3.zig @@ -0,0 +1,10 @@ +pub fn main() void { + const a: anyerror!u32 = error.B; + _ = &(a catch |err| assert(err == error.B)); +} +fn assert(b: bool) void { + if (!b) unreachable; +} + +// run +// diff --git a/test/incremental/catch_at_comptime.4.zig b/test/incremental/catch_at_comptime.4.zig new file mode 100644 index 0000000000..57cb602641 --- /dev/null +++ b/test/incremental/catch_at_comptime.4.zig @@ -0,0 +1,10 @@ +pub fn main() void { + const a: anyerror!u32 = error.Bar; + a catch |err| assert(err == error.Bar); +} +fn assert(b: bool) void { + if (!b) unreachable; +} + +// run +// diff --git a/test/incremental/compile_error.zig b/test/incremental/compile_error.zig new file mode 100644 index 0000000000..dab0f7f7cc --- /dev/null +++ b/test/incremental/compile_error.zig @@ -0,0 +1,7 @@ +export fn foo() void { + @compileError("this is an error"); +} + +// error +// +// :2:5: error: this is an error diff --git a/test/incremental/compile_error_in_inline_fn_call_fixed.0.zig b/test/incremental/compile_error_in_inline_fn_call_fixed.0.zig new file mode 100644 index 0000000000..1848490b07 --- /dev/null +++ b/test/incremental/compile_error_in_inline_fn_call_fixed.0.zig @@ -0,0 +1,16 @@ +pub fn main() void { + var x: usize = 3; + const y = add(10, 2, x); + if (y - 6 != 0) unreachable; +} + +inline fn add(a: usize, b: usize, c: usize) usize { + if (a == 10) @compileError("bad"); + return a + b + c; +} + +// error +// output_mode=Exe +// +// :8:18: error: bad +// :3:18: note: called from here diff --git a/test/incremental/compile_error_in_inline_fn_call_fixed.1.zig b/test/incremental/compile_error_in_inline_fn_call_fixed.1.zig new file mode 100644 index 0000000000..1e61c6c790 --- /dev/null +++ b/test/incremental/compile_error_in_inline_fn_call_fixed.1.zig @@ -0,0 +1,13 @@ +pub fn main() void { + var x: usize = 3; + const y = add(1, 2, x); + if (y - 6 != 0) unreachable; +} + +inline fn add(a: usize, b: usize, c: usize) usize { + if (a == 10) @compileError("bad"); + return a + b + c; +} + +// run +// diff --git a/test/incremental/compile_log.0.zig b/test/incremental/compile_log.0.zig new file mode 100644 index 0000000000..c213ebb930 --- /dev/null +++ b/test/incremental/compile_log.0.zig @@ -0,0 +1,17 @@ +export fn _start() noreturn { + const b = true; + var f: u32 = 1; + @compileLog(b, 20, f, x); + @compileLog(1000); + var bruh: usize = true; + _ = bruh; + unreachable; +} +export fn other() void { + @compileLog(1234); +} +fn x() void {} + +// error +// +// :6:23: error: expected usize, found bool diff --git a/test/incremental/compile_log.1.zig b/test/incremental/compile_log.1.zig new file mode 100644 index 0000000000..12e6641542 --- /dev/null +++ b/test/incremental/compile_log.1.zig @@ -0,0 +1,16 @@ +export fn _start() noreturn { + const b = true; + var f: u32 = 1; + @compileLog(b, 20, f, x); + @compileLog(1000); + unreachable; +} +export fn other() void { + @compileLog(1234); +} +fn x() void {} + +// error +// +// :9:5: error: found compile log statement +// :4:5: note: also here diff --git a/test/incremental/comptime_var.0.zig b/test/incremental/comptime_var.0.zig new file mode 100644 index 0000000000..019cf78abb --- /dev/null +++ b/test/incremental/comptime_var.0.zig @@ -0,0 +1,12 @@ +pub fn main() void { + var a: u32 = 0; + comptime var b: u32 = 0; + if (a == 0) b = 3; +} + +// error +// output_mode=Exe +// target=x86_64-linux,x86_64-macos +// +// :4:21: error: store to comptime variable depends on runtime condition +// :4:11: note: runtime condition here diff --git a/test/incremental/comptime_var.1.zig b/test/incremental/comptime_var.1.zig new file mode 100644 index 0000000000..efc51aafe3 --- /dev/null +++ b/test/incremental/comptime_var.1.zig @@ -0,0 +1,13 @@ +pub fn main() void { + var a: u32 = 0; + comptime var b: u32 = 0; + switch (a) { + 0 => {}, + else => b = 3, + } +} + +// error +// +// :6:21: error: store to comptime variable depends on runtime condition +// :4:13: note: runtime condition here diff --git a/test/incremental/comptime_var.2.zig b/test/incremental/comptime_var.2.zig new file mode 100644 index 0000000000..e91c0540ef --- /dev/null +++ b/test/incremental/comptime_var.2.zig @@ -0,0 +1,34 @@ +const builtin = @import("builtin"); + +extern "c" fn write(usize, usize, usize) usize; + +pub fn main() void { + comptime var len: u32 = 5; + print(len); + len += 9; + print(len); +} + +fn print(len: usize) void { + switch (builtin.os.tag) { + .linux => { + asm volatile ("syscall" + : + : [number] "{rax}" (1), + [arg1] "{rdi}" (1), + [arg2] "{rsi}" (@ptrToInt("Hello, World!\n")), + [arg3] "{rdx}" (len), + : "rcx", "r11", "memory" + ); + }, + .macos => { + _ = write(1, @ptrToInt("Hello, World!\n"), len); + }, + else => unreachable, + } +} + +// run +// +// HelloHello, World! +// diff --git a/test/incremental/comptime_var.3.zig b/test/incremental/comptime_var.3.zig new file mode 100644 index 0000000000..d4e6d85d9d --- /dev/null +++ b/test/incremental/comptime_var.3.zig @@ -0,0 +1,10 @@ +comptime { + var x: i32 = 1; + x += 1; + if (x != 1) unreachable; +} +pub fn main() void {} + +// error +// +// :4:17: error: unable to resolve comptime value diff --git a/test/incremental/comptime_var.4.zig b/test/incremental/comptime_var.4.zig new file mode 100644 index 0000000000..74da6ef448 --- /dev/null +++ b/test/incremental/comptime_var.4.zig @@ -0,0 +1,9 @@ +pub fn main() void { + comptime var i: u64 = 0; + while (i < 5) : (i += 1) {} +} + +// error +// +// :3:24: error: cannot store to comptime variable in non-inline loop +// :3:5: note: non-inline loop here diff --git a/test/incremental/comptime_var.5.zig b/test/incremental/comptime_var.5.zig new file mode 100644 index 0000000000..76a06f3d4b --- /dev/null +++ b/test/incremental/comptime_var.5.zig @@ -0,0 +1,15 @@ +pub fn main() void { + var a: u32 = 0; + if (a == 0) { + comptime var b: u32 = 0; + b = 1; + } +} +comptime { + var x: i32 = 1; + x += 1; + if (x != 2) unreachable; +} + +// run +// diff --git a/test/incremental/comptime_var.6.zig b/test/incremental/comptime_var.6.zig new file mode 100644 index 0000000000..0eb743a05b --- /dev/null +++ b/test/incremental/comptime_var.6.zig @@ -0,0 +1,32 @@ +const builtin = @import("builtin"); + +extern "c" fn write(usize, usize, usize) usize; + +pub fn main() void { + comptime var i: u64 = 2; + inline while (i < 6) : (i += 1) { + print(i); + } +} +fn print(len: usize) void { + switch (builtin.os.tag) { + .linux => { + asm volatile ("syscall" + : + : [number] "{rax}" (1), + [arg1] "{rdi}" (1), + [arg2] "{rsi}" (@ptrToInt("Hello")), + [arg3] "{rdx}" (len), + : "rcx", "r11", "memory" + ); + }, + .macos => { + _ = write(1, @ptrToInt("Hello"), len); + }, + else => unreachable, + } +} + +// run +// +// HeHelHellHello diff --git a/test/incremental/double_ampersand.0.zig b/test/incremental/double_ampersand.0.zig new file mode 100644 index 0000000000..b14c30ecb0 --- /dev/null +++ b/test/incremental/double_ampersand.0.zig @@ -0,0 +1,6 @@ +pub const a = if (true && false) 1 else 2; + +// error +// output_mode=Exe +// +// :1:24: error: ambiguous use of '&&'; use 'and' for logical AND, or change whitespace to ' & &' for bitwise AND diff --git a/test/incremental/double_ampersand.1.zig b/test/incremental/double_ampersand.1.zig new file mode 100644 index 0000000000..cd5bba02fd --- /dev/null +++ b/test/incremental/double_ampersand.1.zig @@ -0,0 +1,11 @@ +pub fn main() void { + const a = true; + const b = false; + _ = a & &b; +} + +// error +// +// :4:11: error: incompatible types: 'bool' and '*const bool' +// :4:9: note: type 'bool' here +// :4:13: note: type '*const bool' here diff --git a/test/incremental/double_ampersand.2.zig b/test/incremental/double_ampersand.2.zig new file mode 100644 index 0000000000..c6f461d661 --- /dev/null +++ b/test/incremental/double_ampersand.2.zig @@ -0,0 +1,7 @@ +pub fn main() void { + const b: u8 = 1; + _ = &&b; +} + +// run +// diff --git a/test/incremental/extern_variable_has_no_type.0.zig b/test/incremental/extern_variable_has_no_type.0.zig new file mode 100644 index 0000000000..2f03067b3a --- /dev/null +++ b/test/incremental/extern_variable_has_no_type.0.zig @@ -0,0 +1,9 @@ +comptime { + const x = foo + foo; + _ = x; +} +extern var foo: i32; + +// error +// +// :2:15: error: unable to resolve comptime value diff --git a/test/incremental/extern_variable_has_no_type.1.zig b/test/incremental/extern_variable_has_no_type.1.zig new file mode 100644 index 0000000000..f5c31244e5 --- /dev/null +++ b/test/incremental/extern_variable_has_no_type.1.zig @@ -0,0 +1,8 @@ +export fn entry() void { + _ = foo; +} +extern var foo; + +// error +// +// :4:8: error: unable to infer variable type diff --git a/test/incremental/function_redeclaration.zig b/test/incremental/function_redeclaration.zig new file mode 100644 index 0000000000..a9664646c9 --- /dev/null +++ b/test/incremental/function_redeclaration.zig @@ -0,0 +1,14 @@ +// dummy comment +fn entry() void {} +fn entry() void {} + +fn foo() void { + var foo = 1234; +} + +// error +// +// :3:1: error: redeclaration of 'entry' +// :2:1: note: other declaration here +// :6:9: error: local shadows declaration of 'foo' +// :5:1: note: declared here diff --git a/test/incremental/global_variable_redeclaration.zig b/test/incremental/global_variable_redeclaration.zig new file mode 100644 index 0000000000..9a0d5939fb --- /dev/null +++ b/test/incremental/global_variable_redeclaration.zig @@ -0,0 +1,8 @@ +// dummy comment +var foo = false; +var foo = true; + +// error +// +// :3:1: error: redeclaration of 'foo' +// :2:1: note: other declaration here diff --git a/test/incremental/hello_world_with_updates_x86_64_linux.0.zig b/test/incremental/hello_world_with_updates_x86_64_linux.0.zig new file mode 100644 index 0000000000..960fae5e64 --- /dev/null +++ b/test/incremental/hello_world_with_updates_x86_64_linux.0.zig @@ -0,0 +1,5 @@ +// error +// output_mode=Exe +// target=x86_64-linux +// +// :109:9: error: struct 'tmp.tmp' has no member named 'main' diff --git a/test/incremental/hello_world_with_updates_x86_64_linux.1.zig b/test/incremental/hello_world_with_updates_x86_64_linux.1.zig new file mode 100644 index 0000000000..0f347b7f50 --- /dev/null +++ b/test/incremental/hello_world_with_updates_x86_64_linux.1.zig @@ -0,0 +1,5 @@ +pub export fn _start() noreturn {} + +// error +// +// :1:34: error: expected noreturn, found void diff --git a/test/incremental/hello_world_with_updates_x86_64_linux.2.zig b/test/incremental/hello_world_with_updates_x86_64_linux.2.zig new file mode 100644 index 0000000000..fcea1870ce --- /dev/null +++ b/test/incremental/hello_world_with_updates_x86_64_linux.2.zig @@ -0,0 +1,32 @@ +pub export fn _start() noreturn { + print(); + + exit(); +} + +fn print() void { + asm volatile ("syscall" + : + : [number] "{rax}" (1), + [arg1] "{rdi}" (1), + [arg2] "{rsi}" (@ptrToInt("Hello, World!\n")), + [arg3] "{rdx}" (14), + : "rcx", "r11", "memory" + ); + return; +} + +fn exit() noreturn { + asm volatile ("syscall" + : + : [number] "{rax}" (231), + [arg1] "{rdi}" (0), + : "rcx", "r11", "memory" + ); + unreachable; +} + +// run +// +// Hello, World! +// diff --git a/test/incremental/hello_world_with_updates_x86_64_linux.3.zig b/test/incremental/hello_world_with_updates_x86_64_linux.3.zig new file mode 100644 index 0000000000..7812023372 --- /dev/null +++ b/test/incremental/hello_world_with_updates_x86_64_linux.3.zig @@ -0,0 +1,20 @@ +pub fn main() void { + print(); +} + +fn print() void { + asm volatile ("syscall" + : + : [number] "{rax}" (1), + [arg1] "{rdi}" (1), + [arg2] "{rsi}" (@ptrToInt("Hello, World!\n")), + [arg3] "{rdx}" (14), + : "rcx", "r11", "memory" + ); + return; +} + +// run +// +// Hello, World! +// diff --git a/test/incremental/hello_world_with_updates_x86_64_linux.4.zig b/test/incremental/hello_world_with_updates_x86_64_linux.4.zig new file mode 100644 index 0000000000..cdf47012b8 --- /dev/null +++ b/test/incremental/hello_world_with_updates_x86_64_linux.4.zig @@ -0,0 +1,20 @@ +pub fn main() void { + print(); +} + +fn print() void { + asm volatile ("syscall" + : + : [number] "{rax}" (1), + [arg1] "{rdi}" (1), + [arg2] "{rsi}" (@ptrToInt("What is up? This is a longer message that will force the data to be relocated in virtual address space.\n")), + [arg3] "{rdx}" (104), + : "rcx", "r11", "memory" + ); + return; +} + +// run +// +// What is up? This is a longer message that will force the data to be relocated in virtual address space. +// diff --git a/test/incremental/hello_world_with_updates_x86_64_linux.5.zig b/test/incremental/hello_world_with_updates_x86_64_linux.5.zig new file mode 100644 index 0000000000..68c1e305f7 --- /dev/null +++ b/test/incremental/hello_world_with_updates_x86_64_linux.5.zig @@ -0,0 +1,22 @@ +pub fn main() void { + print(); + print(); +} + +fn print() void { + asm volatile ("syscall" + : + : [number] "{rax}" (1), + [arg1] "{rdi}" (1), + [arg2] "{rsi}" (@ptrToInt("What is up? This is a longer message that will force the data to be relocated in virtual address space.\n")), + [arg3] "{rdx}" (104), + : "rcx", "r11", "memory" + ); + return; +} + +// run +// +// What is up? This is a longer message that will force the data to be relocated in virtual address space. +// What is up? This is a longer message that will force the data to be relocated in virtual address space. +// diff --git a/test/incremental/hello_world_with_updates_x86_64_macos.0.zig b/test/incremental/hello_world_with_updates_x86_64_macos.0.zig new file mode 100644 index 0000000000..34440c4603 --- /dev/null +++ b/test/incremental/hello_world_with_updates_x86_64_macos.0.zig @@ -0,0 +1,5 @@ +// error +// output_mode=Exe +// target=x86_64-macos +// +// :109:9: error: struct 'tmp.tmp' has no member named 'main' diff --git a/test/incremental/hello_world_with_updates_x86_64_macos.1.zig b/test/incremental/hello_world_with_updates_x86_64_macos.1.zig new file mode 100644 index 0000000000..909fc9ccfb --- /dev/null +++ b/test/incremental/hello_world_with_updates_x86_64_macos.1.zig @@ -0,0 +1,5 @@ +pub export fn main() noreturn {} + +// error +// +// :1:32: error: expected noreturn, found void diff --git a/test/incremental/hello_world_with_updates_x86_64_macos.2.zig b/test/incremental/hello_world_with_updates_x86_64_macos.2.zig new file mode 100644 index 0000000000..fb8cb39edd --- /dev/null +++ b/test/incremental/hello_world_with_updates_x86_64_macos.2.zig @@ -0,0 +1,19 @@ +extern "c" fn write(usize, usize, usize) usize; +extern "c" fn exit(usize) noreturn; + +pub export fn main() noreturn { + print(); + + exit(0); +} + +fn print() void { + const msg = @ptrToInt("Hello, World!\n"); + const len = 14; + _ = write(1, msg, len); +} + +// run +// +// Hello, World! +// diff --git a/test/incremental/hello_world_with_updates_x86_64_macos.3.zig b/test/incremental/hello_world_with_updates_x86_64_macos.3.zig new file mode 100644 index 0000000000..f6e233886b --- /dev/null +++ b/test/incremental/hello_world_with_updates_x86_64_macos.3.zig @@ -0,0 +1,16 @@ +extern "c" fn write(usize, usize, usize) usize; + +pub fn main() void { + print(); +} + +fn print() void { + const msg = @ptrToInt("Hello, World!\n"); + const len = 14; + _ = write(1, msg, len); +} + +// run +// +// Hello, World! +// diff --git a/test/incremental/hello_world_with_updates_x86_64_macos.4.zig b/test/incremental/hello_world_with_updates_x86_64_macos.4.zig new file mode 100644 index 0000000000..f89cef7354 --- /dev/null +++ b/test/incremental/hello_world_with_updates_x86_64_macos.4.zig @@ -0,0 +1,22 @@ +extern "c" fn write(usize, usize, usize) usize; + +pub fn main() void { + print(); + print(); + print(); + print(); +} + +fn print() void { + const msg = @ptrToInt("Hello, World!\n"); + const len = 14; + _ = write(1, msg, len); +} + +// run +// +// Hello, World! +// Hello, World! +// Hello, World! +// Hello, World! +// diff --git a/test/incremental/hello_world_with_updates_x86_64_macos.5.zig b/test/incremental/hello_world_with_updates_x86_64_macos.5.zig new file mode 100644 index 0000000000..0d7f97578a --- /dev/null +++ b/test/incremental/hello_world_with_updates_x86_64_macos.5.zig @@ -0,0 +1,16 @@ +extern "c" fn write(usize, usize, usize) usize; + +pub fn main() void { + print(); +} + +fn print() void { + const msg = @ptrToInt("What is up? This is a longer message that will force the data to be relocated in virtual address space.\n"); + const len = 104; + _ = write(1, msg, len); +} + +// run +// +// What is up? This is a longer message that will force the data to be relocated in virtual address space. +// diff --git a/test/incremental/hello_world_with_updates_x86_64_macos.6.zig b/test/incremental/hello_world_with_updates_x86_64_macos.6.zig new file mode 100644 index 0000000000..3ce2cb7176 --- /dev/null +++ b/test/incremental/hello_world_with_updates_x86_64_macos.6.zig @@ -0,0 +1,18 @@ +extern "c" fn write(usize, usize, usize) usize; + +pub fn main() void { + print(); + print(); +} + +fn print() void { + const msg = @ptrToInt("What is up? This is a longer message that will force the data to be relocated in virtual address space.\n"); + const len = 104; + _ = write(1, msg, len); +} + +// run +// +// What is up? This is a longer message that will force the data to be relocated in virtual address space. +// What is up? This is a longer message that will force the data to be relocated in virtual address space. +// diff --git a/test/incremental/inline_assembly_x86_64_linux.0.zig b/test/incremental/inline_assembly_x86_64_linux.0.zig new file mode 100644 index 0000000000..e3c0f3badb --- /dev/null +++ b/test/incremental/inline_assembly_x86_64_linux.0.zig @@ -0,0 +1,16 @@ +pub fn main() void { + const number = 1234; + const x = asm volatile ("syscall" + : [o] "{rax}" (-> number), + : [number] "{rax}" (231), + [arg1] "{rdi}" (60), + : "rcx", "r11", "memory" + ); + _ = x; +} + +// error +// output_mode=Exe +// target=x86_64-linux +// +// :4:27: error: expected type, found comptime_int diff --git a/test/incremental/inline_assembly_x86_64_linux.1.zig b/test/incremental/inline_assembly_x86_64_linux.1.zig new file mode 100644 index 0000000000..b35014b0f6 --- /dev/null +++ b/test/incremental/inline_assembly_x86_64_linux.1.zig @@ -0,0 +1,15 @@ +const S = struct { + comptime { + asm volatile ( + \\zig_moment: + \\syscall + ); + } +}; +pub fn main() void { + _ = S; +} + +// error +// +// :3:13: error: volatile is meaningless on global assembly diff --git a/test/incremental/inline_assembly_x86_64_linux.2.zig b/test/incremental/inline_assembly_x86_64_linux.2.zig new file mode 100644 index 0000000000..1695265ab4 --- /dev/null +++ b/test/incremental/inline_assembly_x86_64_linux.2.zig @@ -0,0 +1,12 @@ +pub fn main() void { + var bruh: u32 = 1; + asm ("" + : + : [bruh] "{rax}" (4) + : "memory" + ); +} + +// error +// +// :3:5: error: assembly expression with no output must be marked volatile diff --git a/test/incremental/inline_assembly_x86_64_linux.3.zig b/test/incremental/inline_assembly_x86_64_linux.3.zig new file mode 100644 index 0000000000..765eaeb97e --- /dev/null +++ b/test/incremental/inline_assembly_x86_64_linux.3.zig @@ -0,0 +1,12 @@ +pub fn main() void {} +comptime { + asm ("" + : + : [bruh] "{rax}" (4) + : "memory" + ); +} + +// error +// +// :3:5: error: global assembly cannot have inputs, outputs, or clobbers diff --git a/test/incremental/inner_func_accessing_outer_var.zig b/test/incremental/inner_func_accessing_outer_var.zig new file mode 100644 index 0000000000..e30cf58ef8 --- /dev/null +++ b/test/incremental/inner_func_accessing_outer_var.zig @@ -0,0 +1,15 @@ +pub fn f() void { + var bar: bool = true; + const S = struct { + fn baz() bool { + return bar; + } + }; + _ = S; +} + +// error +// +// :5:20: error: mutable 'bar' not accessible from here +// :2:9: note: declared mutable here +// :3:15: note: crosses namespace boundary here diff --git a/test/incremental/int_to_ptr.0.zig b/test/incremental/int_to_ptr.0.zig new file mode 100644 index 0000000000..b7c70b90a4 --- /dev/null +++ b/test/incremental/int_to_ptr.0.zig @@ -0,0 +1,8 @@ +pub fn main() void { + _ = @intToPtr(*u8, 0); +} + +// error +// output_mode=Exe +// +// :2:24: error: pointer type '*u8' does not allow address zero diff --git a/test/incremental/int_to_ptr.1.zig b/test/incremental/int_to_ptr.1.zig new file mode 100644 index 0000000000..72c8c8c9d6 --- /dev/null +++ b/test/incremental/int_to_ptr.1.zig @@ -0,0 +1,7 @@ +pub fn main() void { + _ = @intToPtr(*u32, 2); +} + +// error +// +// :2:25: error: pointer type '*u32' requires aligned address diff --git a/test/incremental/issue_10138_callee_preserved_regs_working_x86_64_linux.zig b/test/incremental/issue_10138_callee_preserved_regs_working_x86_64_linux.zig new file mode 100644 index 0000000000..4c045496da --- /dev/null +++ b/test/incremental/issue_10138_callee_preserved_regs_working_x86_64_linux.zig @@ -0,0 +1,31 @@ +pub fn main() void { + const fd = open(); + _ = write(fd, "a", 1); + _ = close(fd); +} + +fn open() usize { + return 42; +} + +fn write(fd: usize, a: [*]const u8, len: usize) usize { + return syscall4(.WRITE, fd, @ptrToInt(a), len); +} + +fn syscall4(n: enum { WRITE }, a: usize, b: usize, c: usize) usize { + _ = n; + _ = a; + _ = b; + _ = c; + return 23; +} + +fn close(fd: usize) usize { + if (fd != 42) + unreachable; + return 0; +} + +// run +// target=x86_64-linux +// diff --git a/test/incremental/issue_7187_miscompilation_with_bool_return_type.zig b/test/incremental/issue_7187_miscompilation_with_bool_return_type.zig new file mode 100644 index 0000000000..3aed8685bf --- /dev/null +++ b/test/incremental/issue_7187_miscompilation_with_bool_return_type.zig @@ -0,0 +1,18 @@ +pub fn main() void { + var x: usize = 1; + var y: bool = getFalse(); + _ = y; + + assert(x == 1); +} + +fn getFalse() bool { + return false; +} + +fn assert(ok: bool) void { + if (!ok) unreachable; +} + +// run +// diff --git a/test/incremental/load_store_via_pointer_deref.0.zig b/test/incremental/load_store_via_pointer_deref.0.zig new file mode 100644 index 0000000000..96aedf3196 --- /dev/null +++ b/test/incremental/load_store_via_pointer_deref.0.zig @@ -0,0 +1,16 @@ +pub fn main() void { + var x: u32 = undefined; + set(&x); + assert(x == 123); +} + +fn set(x: *u32) void { + x.* = 123; +} + +fn assert(ok: bool) void { + if (!ok) unreachable; +} + +// run +// diff --git a/test/incremental/load_store_via_pointer_deref.1.zig b/test/incremental/load_store_via_pointer_deref.1.zig new file mode 100644 index 0000000000..e311092744 --- /dev/null +++ b/test/incremental/load_store_via_pointer_deref.1.zig @@ -0,0 +1,16 @@ +pub fn main() void { + var x: u16 = undefined; + set(&x); + assert(x == 123); +} + +fn set(x: *u16) void { + x.* = 123; +} + +fn assert(ok: bool) void { + if (!ok) unreachable; +} + +// run +// diff --git a/test/incremental/load_store_via_pointer_deref.2.zig b/test/incremental/load_store_via_pointer_deref.2.zig new file mode 100644 index 0000000000..3b1484faa1 --- /dev/null +++ b/test/incremental/load_store_via_pointer_deref.2.zig @@ -0,0 +1,16 @@ +pub fn main() void { + var x: u8 = undefined; + set(&x); + assert(x == 123); +} + +fn set(x: *u8) void { + x.* = 123; +} + +fn assert(ok: bool) void { + if (!ok) unreachable; +} + +// run +// diff --git a/test/incremental/lower_unnamed_consts_structs.0.zig b/test/incremental/lower_unnamed_consts_structs.0.zig new file mode 100644 index 0000000000..3123299646 --- /dev/null +++ b/test/incremental/lower_unnamed_consts_structs.0.zig @@ -0,0 +1,25 @@ +const Foo = struct { + a: u8, + b: u32, + + fn first(self: *Foo) u8 { + return self.a; + } + + fn second(self: *Foo) u32 { + return self.b; + } +}; + +pub fn main() void { + var foo = Foo{ .a = 1, .b = 5 }; + assert(foo.first() == 1); + assert(foo.second() == 5); +} + +fn assert(ok: bool) void { + if (!ok) unreachable; +} + +// run +// diff --git a/test/incremental/lower_unnamed_consts_structs.1.zig b/test/incremental/lower_unnamed_consts_structs.1.zig new file mode 100644 index 0000000000..37afdc8a09 --- /dev/null +++ b/test/incremental/lower_unnamed_consts_structs.1.zig @@ -0,0 +1,35 @@ +const Foo = struct { + a: u8, + b: u32, + + fn first(self: *Foo) u8 { + return self.a; + } + + fn second(self: *Foo) u32 { + return self.b; + } +}; + +pub fn main() void { + var foo = Foo{ .a = 1, .b = 5 }; + assert(foo.first() == 1); + assert(foo.second() == 5); + + foo.a = 10; + foo.b = 255; + + assert(foo.first() == 10); + assert(foo.second() == 255); + + var foo2 = Foo{ .a = 15, .b = 255 }; + assert(foo2.first() == 15); + assert(foo2.second() == 255); +} + +fn assert(ok: bool) void { + if (!ok) unreachable; +} + +// run +// diff --git a/test/incremental/lower_unnamed_consts_structs.2.zig b/test/incremental/lower_unnamed_consts_structs.2.zig new file mode 100644 index 0000000000..b437c4a030 --- /dev/null +++ b/test/incremental/lower_unnamed_consts_structs.2.zig @@ -0,0 +1,25 @@ +const Foo = struct { + a: u8, + b: u32, + + fn first(self: *Foo) u8 { + return self.a; + } + + fn second(self: *Foo) u32 { + return self.b; + } +}; + +pub fn main() void { + var foo2 = Foo{ .a = 15, .b = 255 }; + assert(foo2.first() == 15); + assert(foo2.second() == 255); +} + +fn assert(ok: bool) void { + if (!ok) unreachable; +} + +// run +// diff --git a/test/incremental/merge_error_sets.0.zig b/test/incremental/merge_error_sets.0.zig new file mode 100644 index 0000000000..f1f3b96883 --- /dev/null +++ b/test/incremental/merge_error_sets.0.zig @@ -0,0 +1,18 @@ +pub fn main() void { + const E = error{ A, B, D } || error{ A, B, C }; + E.A catch {}; + E.B catch {}; + E.C catch {}; + E.D catch {}; + const E2 = error{ X, Y } || @TypeOf(error.Z); + E2.X catch {}; + E2.Y catch {}; + E2.Z catch {}; + assert(anyerror || error{Z} == anyerror); +} +fn assert(b: bool) void { + if (!b) unreachable; +} + +// run +// diff --git a/test/incremental/merge_error_sets.1.zig b/test/incremental/merge_error_sets.1.zig new file mode 100644 index 0000000000..81c1cad134 --- /dev/null +++ b/test/incremental/merge_error_sets.1.zig @@ -0,0 +1,9 @@ +pub fn main() void { + const z = true || false; + _ = z; +} + +// error +// +// :2:15: error: expected error set type, found 'bool' +// :2:20: note: '||' merges error sets; 'or' performs boolean OR diff --git a/test/incremental/only_1_function_and_it_gets_updated_x86_64_linux.0.zig b/test/incremental/only_1_function_and_it_gets_updated_x86_64_linux.0.zig new file mode 100644 index 0000000000..ecba1c8133 --- /dev/null +++ b/test/incremental/only_1_function_and_it_gets_updated_x86_64_linux.0.zig @@ -0,0 +1,13 @@ +pub export fn _start() noreturn { + asm volatile ("syscall" + : + : [number] "{rax}" (60), // exit + [arg1] "{rdi}" (0), + : "rcx", "r11", "memory" + ); + unreachable; +} + +// run +// target=x86_64-linux +// diff --git a/test/incremental/only_1_function_and_it_gets_updated_x86_64_linux.1.zig b/test/incremental/only_1_function_and_it_gets_updated_x86_64_linux.1.zig new file mode 100644 index 0000000000..529acbcf38 --- /dev/null +++ b/test/incremental/only_1_function_and_it_gets_updated_x86_64_linux.1.zig @@ -0,0 +1,12 @@ +pub export fn _start() noreturn { + asm volatile ("syscall" + : + : [number] "{rax}" (231), // exit_group + [arg1] "{rdi}" (0), + : "rcx", "r11", "memory" + ); + unreachable; +} + +// run +// diff --git a/test/incremental/optional_payload.0.zig b/test/incremental/optional_payload.0.zig new file mode 100644 index 0000000000..65296875ff --- /dev/null +++ b/test/incremental/optional_payload.0.zig @@ -0,0 +1,19 @@ +pub fn main() void { + var x: u32 = undefined; + const maybe_x = byPtr(&x); + assert(maybe_x != null); + maybe_x.?.* = 123; + assert(x == 123); +} + +fn byPtr(x: *u32) ?*u32 { + return x; +} + +fn assert(ok: bool) void { + if (!ok) unreachable; +} + +// run +// target=x86_64-linux,x86_64-macos +// diff --git a/test/incremental/optional_payload.1.zig b/test/incremental/optional_payload.1.zig new file mode 100644 index 0000000000..2d4dafffb9 --- /dev/null +++ b/test/incremental/optional_payload.1.zig @@ -0,0 +1,17 @@ +pub fn main() void { + var x: u32 = undefined; + const maybe_x = byPtr(&x); + assert(maybe_x == null); +} + +fn byPtr(x: *u32) ?*u32 { + _ = x; + return null; +} + +fn assert(ok: bool) void { + if (!ok) unreachable; +} + +// run +// diff --git a/test/incremental/optional_payload.2.zig b/test/incremental/optional_payload.2.zig new file mode 100644 index 0000000000..608310923b --- /dev/null +++ b/test/incremental/optional_payload.2.zig @@ -0,0 +1,18 @@ +pub fn main() void { + var x: u8 = undefined; + const maybe_x = byPtr(&x); + assert(maybe_x != null); + maybe_x.?.* = 255; + assert(x == 255); +} + +fn byPtr(x: *u8) ?*u8 { + return x; +} + +fn assert(ok: bool) void { + if (!ok) unreachable; +} + +// run +// diff --git a/test/incremental/optional_payload.3.zig b/test/incremental/optional_payload.3.zig new file mode 100644 index 0000000000..b81ec398c7 --- /dev/null +++ b/test/incremental/optional_payload.3.zig @@ -0,0 +1,18 @@ +pub fn main() void { + var x: i8 = undefined; + const maybe_x = byPtr(&x); + assert(maybe_x != null); + maybe_x.?.* = -1; + assert(x == -1); +} + +fn byPtr(x: *i8) ?*i8 { + return x; +} + +fn assert(ok: bool) void { + if (!ok) unreachable; +} + +// run +// diff --git a/test/incremental/orelse_at_comptime.0.zig b/test/incremental/orelse_at_comptime.0.zig new file mode 100644 index 0000000000..5397ca3b0a --- /dev/null +++ b/test/incremental/orelse_at_comptime.0.zig @@ -0,0 +1,11 @@ +pub fn main() void { + const i: ?u64 = 0; + const result = i orelse 5; + assert(result == 0); +} +fn assert(b: bool) void { + if (!b) unreachable; +} + +// run +// diff --git a/test/incremental/orelse_at_comptime.1.zig b/test/incremental/orelse_at_comptime.1.zig new file mode 100644 index 0000000000..7d4fcd3178 --- /dev/null +++ b/test/incremental/orelse_at_comptime.1.zig @@ -0,0 +1,11 @@ +pub fn main() void { + const i: ?u64 = null; + const result = i orelse 5; + assert(result == 5); +} +fn assert(b: bool) void { + if (!b) unreachable; +} + +// run +// diff --git a/test/incremental/passing_u0_to_function.zig b/test/incremental/passing_u0_to_function.zig new file mode 100644 index 0000000000..f84c30be8a --- /dev/null +++ b/test/incremental/passing_u0_to_function.zig @@ -0,0 +1,9 @@ +pub fn main() void { + doNothing(0); +} +fn doNothing(arg: u0) void { + _ = arg; +} + +// run +// diff --git a/test/incremental/recursive_inline_function.0.zig b/test/incremental/recursive_inline_function.0.zig new file mode 100644 index 0000000000..c8333c9065 --- /dev/null +++ b/test/incremental/recursive_inline_function.0.zig @@ -0,0 +1,12 @@ +pub fn main() void { + const y = fibonacci(7); + if (y - 21 != 0) unreachable; +} + +inline fn fibonacci(n: usize) usize { + if (n <= 2) return n; + return fibonacci(n - 2) + fibonacci(n - 1); +} + +// run +// diff --git a/test/incremental/recursive_inline_function.1.zig b/test/incremental/recursive_inline_function.1.zig new file mode 100644 index 0000000000..139da1c371 --- /dev/null +++ b/test/incremental/recursive_inline_function.1.zig @@ -0,0 +1,16 @@ +// This additionally tests that the compile error reports the correct source location. +// Without storing source locations relative to the owner decl, the compile error +// here would be off by 2 bytes (from the "7" -> "999"). +pub fn main() void { + const y = fibonacci(999); + if (y - 21 != 0) unreachable; +} + +inline fn fibonacci(n: usize) usize { + if (n <= 2) return n; + return fibonacci(n - 2) + fibonacci(n - 1); +} + +// error +// +// :11:21: error: evaluation exceeded 1000 backwards branches diff --git a/test/incremental/redundant_comptime.0.zig b/test/incremental/redundant_comptime.0.zig new file mode 100644 index 0000000000..c1ecbf7ace --- /dev/null +++ b/test/incremental/redundant_comptime.0.zig @@ -0,0 +1,7 @@ +pub fn main() void { + var a: comptime u32 = 0; +} + +// error +// +// :2:12: error: redundant comptime keyword in already comptime scope diff --git a/test/incremental/redundant_comptime.1.zig b/test/incremental/redundant_comptime.1.zig new file mode 100644 index 0000000000..79226ae8a6 --- /dev/null +++ b/test/incremental/redundant_comptime.1.zig @@ -0,0 +1,9 @@ +pub fn main() void { + comptime { + var a: u32 = comptime 0; + } +} + +// error +// +// :3:22: error: redundant comptime keyword in already comptime scope diff --git a/test/incremental/returns_in_try.zig b/test/incremental/returns_in_try.zig new file mode 100644 index 0000000000..de5a9a3258 --- /dev/null +++ b/test/incremental/returns_in_try.zig @@ -0,0 +1,16 @@ +pub fn main() !void { + try a(); + try b(); +} + +pub fn a() !void { + defer try b(); +} +pub fn b() !void { + defer return a(); +} + +// error +// +// :7:11: error: 'try' not allowed inside defer expression +// :10:11: error: cannot return from defer expression diff --git a/test/incremental/runtime_bitwise_and.zig b/test/incremental/runtime_bitwise_and.zig new file mode 100644 index 0000000000..3ba3d3124c --- /dev/null +++ b/test/incremental/runtime_bitwise_and.zig @@ -0,0 +1,16 @@ +pub fn main() void { + var i: u32 = 10; + var j: u32 = 11; + assert(i & 1 == 0); + assert(j & 1 == 1); + var m1: u32 = 0b1111; + var m2: u32 = 0b0000; + assert(m1 & 0b1010 == 0b1010); + assert(m2 & 0b1010 == 0b0000); +} +fn assert(b: bool) void { + if (!b) unreachable; +} + +// run +// diff --git a/test/incremental/runtime_bitwise_or.zig b/test/incremental/runtime_bitwise_or.zig new file mode 100644 index 0000000000..b97c2acf02 --- /dev/null +++ b/test/incremental/runtime_bitwise_or.zig @@ -0,0 +1,16 @@ +pub fn main() void { + var i: u32 = 10; + var j: u32 = 11; + assert(i | 1 == 11); + assert(j | 1 == 11); + var m1: u32 = 0b1111; + var m2: u32 = 0b0000; + assert(m1 | 0b1010 == 0b1111); + assert(m2 | 0b1010 == 0b1010); +} +fn assert(b: bool) void { + if (!b) unreachable; +} + +// run +// diff --git a/test/incremental/saving_vars_of_different_abi_size_to_stack.0.zig b/test/incremental/saving_vars_of_different_abi_size_to_stack.0.zig new file mode 100644 index 0000000000..6134622a0e --- /dev/null +++ b/test/incremental/saving_vars_of_different_abi_size_to_stack.0.zig @@ -0,0 +1,16 @@ +pub fn main() void { + assert(callMe(2) == 24); +} + +fn callMe(a: u8) u8 { + var b: u8 = a + 10; + const c = 2 * b; + return c; +} + +pub fn assert(ok: bool) void { + if (!ok) unreachable; // assertion failure +} + +// run +// diff --git a/test/incremental/saving_vars_of_different_abi_size_to_stack.1.zig b/test/incremental/saving_vars_of_different_abi_size_to_stack.1.zig new file mode 100644 index 0000000000..4d87d7b9c5 --- /dev/null +++ b/test/incremental/saving_vars_of_different_abi_size_to_stack.1.zig @@ -0,0 +1,16 @@ +pub fn main() void { + assert(callMe(2) == 24); +} + +fn callMe(a: u16) u16 { + var b: u16 = a + 10; + const c = 2 * b; + return c; +} + +pub fn assert(ok: bool) void { + if (!ok) unreachable; // assertion failure +} + +// run +// diff --git a/test/incremental/saving_vars_of_different_abi_size_to_stack.2.zig b/test/incremental/saving_vars_of_different_abi_size_to_stack.2.zig new file mode 100644 index 0000000000..b665227962 --- /dev/null +++ b/test/incremental/saving_vars_of_different_abi_size_to_stack.2.zig @@ -0,0 +1,16 @@ +pub fn main() void { + assert(callMe(2) == 24); +} + +fn callMe(a: u32) u32 { + var b: u32 = a + 10; + const c = 2 * b; + return c; +} + +pub fn assert(ok: bool) void { + if (!ok) unreachable; // assertion failure +} + +// run +// diff --git a/test/incremental/setting_an_address_space_on_a_local_variable.zig b/test/incremental/setting_an_address_space_on_a_local_variable.zig new file mode 100644 index 0000000000..dad282dc31 --- /dev/null +++ b/test/incremental/setting_an_address_space_on_a_local_variable.zig @@ -0,0 +1,8 @@ +export fn entry() i32 { + var foo: i32 addrspace(".general") = 1234; + return foo; +} + +// error +// +// :2:28: error: cannot set address space of local variable 'foo' diff --git a/test/incremental/try_in_comptime_in_struct_in_test.zig b/test/incremental/try_in_comptime_in_struct_in_test.zig new file mode 100644 index 0000000000..e88aa13a7b --- /dev/null +++ b/test/incremental/try_in_comptime_in_struct_in_test.zig @@ -0,0 +1,13 @@ +test "@unionInit on union w/ tag but no fields" { + const S = struct { + comptime { + try expect(false); + } + }; + _ = S; +} + +// error +// is_test=1 +// +// :4:13: error: 'try' outside function scope diff --git a/test/incremental/type_of.0.zig b/test/incremental/type_of.0.zig new file mode 100644 index 0000000000..d8a97d1444 --- /dev/null +++ b/test/incremental/type_of.0.zig @@ -0,0 +1,13 @@ +pub fn main() void { + var x: usize = 0; + _ = x; + const z = @TypeOf(x, @as(u128, 5)); + assert(z == u128); +} + +pub fn assert(ok: bool) void { + if (!ok) unreachable; // assertion failure +} + +// run +// diff --git a/test/incremental/type_of.1.zig b/test/incremental/type_of.1.zig new file mode 100644 index 0000000000..86d7d87a19 --- /dev/null +++ b/test/incremental/type_of.1.zig @@ -0,0 +1,11 @@ +pub fn main() void { + const z = @TypeOf(true); + assert(z == bool); +} + +pub fn assert(ok: bool) void { + if (!ok) unreachable; // assertion failure +} + +// run +// diff --git a/test/incremental/type_of.2.zig b/test/incremental/type_of.2.zig new file mode 100644 index 0000000000..cdbc8121fd --- /dev/null +++ b/test/incremental/type_of.2.zig @@ -0,0 +1,9 @@ +pub fn main() void { + _ = @TypeOf(true, 1); +} + +// error +// +// :2:9: error: incompatible types: 'bool' and 'comptime_int' +// :2:17: note: type 'bool' here +// :2:23: note: type 'comptime_int' here diff --git a/test/incremental/unused_labels.0.zig b/test/incremental/unused_labels.0.zig new file mode 100644 index 0000000000..9afa5facdd --- /dev/null +++ b/test/incremental/unused_labels.0.zig @@ -0,0 +1,8 @@ +comptime { + foo: {} +} + +// error +// output_mode=Exe +// +// :2:5: error: unused block label diff --git a/test/incremental/unused_labels.1.zig b/test/incremental/unused_labels.1.zig new file mode 100644 index 0000000000..c7ff576875 --- /dev/null +++ b/test/incremental/unused_labels.1.zig @@ -0,0 +1,7 @@ +comptime { + foo: while (true) {} +} + +// error +// +// :2:5: error: unused while loop label diff --git a/test/incremental/unused_labels.2.zig b/test/incremental/unused_labels.2.zig new file mode 100644 index 0000000000..babe3c7b0a --- /dev/null +++ b/test/incremental/unused_labels.2.zig @@ -0,0 +1,7 @@ +comptime { + foo: for ("foo") |_| {} +} + +// error +// +// :2:5: error: unused for loop label diff --git a/test/incremental/unused_labels.3.zig b/test/incremental/unused_labels.3.zig new file mode 100644 index 0000000000..e4f3ac05a4 --- /dev/null +++ b/test/incremental/unused_labels.3.zig @@ -0,0 +1,8 @@ +comptime { + blk: {blk: {}} +} + +// error +// +// :2:11: error: redefinition of label 'blk' +// :2:5: note: previous definition here diff --git a/test/incremental/unwrap_error_union_simple_errors.0.zig b/test/incremental/unwrap_error_union_simple_errors.0.zig new file mode 100644 index 0000000000..a1e2da9340 --- /dev/null +++ b/test/incremental/unwrap_error_union_simple_errors.0.zig @@ -0,0 +1,10 @@ +pub fn main() void { + maybeErr() catch unreachable; +} + +fn maybeErr() !void { + return; +} + +// run +// diff --git a/test/incremental/unwrap_error_union_simple_errors.1.zig b/test/incremental/unwrap_error_union_simple_errors.1.zig new file mode 100644 index 0000000000..830ee629bc --- /dev/null +++ b/test/incremental/unwrap_error_union_simple_errors.1.zig @@ -0,0 +1,11 @@ +pub fn main() void { + maybeErr() catch return; + unreachable; +} + +fn maybeErr() !void { + return error.NoWay; +} + +// run +// diff --git a/test/incremental/variable_shadowing.0.zig b/test/incremental/variable_shadowing.0.zig new file mode 100644 index 0000000000..0ab53a78f9 --- /dev/null +++ b/test/incremental/variable_shadowing.0.zig @@ -0,0 +1,9 @@ +pub fn main() void { + var i: u32 = 10; + var i: u32 = 10; +} + +// error +// +// :3:9: error: redeclaration of local variable 'i' +// :2:9: note: previous declaration here diff --git a/test/incremental/variable_shadowing.1.zig b/test/incremental/variable_shadowing.1.zig new file mode 100644 index 0000000000..af24af038d --- /dev/null +++ b/test/incremental/variable_shadowing.1.zig @@ -0,0 +1,9 @@ +var testing: i64 = 10; +pub fn main() void { + var testing: i64 = 20; +} + +// error +// +// :3:9: error: local shadows declaration of 'testing' +// :1:1: note: declared here diff --git a/test/incremental/variable_shadowing.2.zig b/test/incremental/variable_shadowing.2.zig new file mode 100644 index 0000000000..a44372f9b9 --- /dev/null +++ b/test/incremental/variable_shadowing.2.zig @@ -0,0 +1,13 @@ +fn a() type { + return struct { + pub fn b() void { + const c = 6; + const c = 69; + } + }; +} + +// error +// +// :5:19: error: redeclaration of local constant 'c' +// :4:19: note: previous declaration here diff --git a/test/incremental/variable_shadowing.3.zig b/test/incremental/variable_shadowing.3.zig new file mode 100644 index 0000000000..89288705e1 --- /dev/null +++ b/test/incremental/variable_shadowing.3.zig @@ -0,0 +1,10 @@ +pub fn main() void { + var i = 0; + for ("n") |_, i| { + } +} + +// error +// +// :3:19: error: redeclaration of local variable 'i' +// :2:9: note: previous declaration here diff --git a/test/incremental/variable_shadowing.4.zig b/test/incremental/variable_shadowing.4.zig new file mode 100644 index 0000000000..b798cc13c1 --- /dev/null +++ b/test/incremental/variable_shadowing.4.zig @@ -0,0 +1,10 @@ +pub fn main() void { + var i = 0; + for ("n") |i| { + } +} + +// error +// +// :3:16: error: redeclaration of local variable 'i' +// :2:9: note: previous declaration here diff --git a/test/incremental/variable_shadowing.5.zig b/test/incremental/variable_shadowing.5.zig new file mode 100644 index 0000000000..484d218ea2 --- /dev/null +++ b/test/incremental/variable_shadowing.5.zig @@ -0,0 +1,10 @@ +pub fn main() void { + var i = 0; + while ("n") |i| { + } +} + +// error +// +// :3:18: error: redeclaration of local variable 'i' +// :2:9: note: previous declaration here diff --git a/test/incremental/variable_shadowing.6.zig b/test/incremental/variable_shadowing.6.zig new file mode 100644 index 0000000000..3e53c4da2f --- /dev/null +++ b/test/incremental/variable_shadowing.6.zig @@ -0,0 +1,13 @@ +pub fn main() void { + var i = 0; + while ("n") |bruh| { + _ = bruh; + } else |i| { + + } +} + +// error +// +// :5:13: error: redeclaration of local variable 'i' +// :2:9: note: previous declaration here diff --git a/test/incremental/variable_shadowing.7.zig b/test/incremental/variable_shadowing.7.zig new file mode 100644 index 0000000000..95888839a7 --- /dev/null +++ b/test/incremental/variable_shadowing.7.zig @@ -0,0 +1,9 @@ +pub fn main() void { + var i = 0; + if (true) |i| {} +} + +// error +// +// :3:16: error: redeclaration of local variable 'i' +// :2:9: note: previous declaration here diff --git a/test/incremental/variable_shadowing.8.zig b/test/incremental/variable_shadowing.8.zig new file mode 100644 index 0000000000..57e616e1d6 --- /dev/null +++ b/test/incremental/variable_shadowing.8.zig @@ -0,0 +1,9 @@ +pub fn main() void { + var i = 0; + if (true) |i| {} else |e| {} +} + +// error +// +// :3:16: error: redeclaration of local variable 'i' +// :2:9: note: previous declaration here diff --git a/test/incremental/variable_shadowing.9.zig b/test/incremental/variable_shadowing.9.zig new file mode 100644 index 0000000000..b8a1198aed --- /dev/null +++ b/test/incremental/variable_shadowing.9.zig @@ -0,0 +1,9 @@ +pub fn main() void { + var i = 0; + if (true) |_| {} else |i| {} +} + +// error +// +// :3:28: error: redeclaration of local variable 'i' +// :2:9: note: previous declaration here