diff options
| author | Matthew Lugg <mlugg@mlugg.co.uk> | 2023-11-19 16:19:06 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-11-19 16:19:06 +0000 |
| commit | 6b1a823b2b30d9318c9877dbdbd3d02fa939fba0 (patch) | |
| tree | 6e5afdad2397ac7224119811583d19107b6e517a /test/cases/compile_errors/async | |
| parent | 325e0f5f0e8a9ce2540ec3ec5b7cbbecac15257a (diff) | |
| parent | 9cf6c1ad11bb5f0247ff3458cba5f3bd156d1fb9 (diff) | |
| download | zig-6b1a823b2b30d9318c9877dbdbd3d02fa939fba0.tar.gz zig-6b1a823b2b30d9318c9877dbdbd3d02fa939fba0.zip | |
Merge pull request #18017 from mlugg/var-never-mutated
compiler: add error for unnecessary use of 'var'
Diffstat (limited to 'test/cases/compile_errors/async')
11 files changed, 17 insertions, 13 deletions
diff --git a/test/cases/compile_errors/async/Frame_of_generic_function.zig b/test/cases/compile_errors/async/Frame_of_generic_function.zig index d90e53eb46..af0fb5c72e 100644 --- a/test/cases/compile_errors/async/Frame_of_generic_function.zig +++ b/test/cases/compile_errors/async/Frame_of_generic_function.zig @@ -1,10 +1,10 @@ export fn entry() void { var frame: @Frame(func) = undefined; - _ = frame; + _ = &frame; } fn func(comptime T: type) void { var x: T = undefined; - _ = x; + _ = &x; } // error diff --git a/test/cases/compile_errors/async/async_function_depends_on_its_own_frame.zig b/test/cases/compile_errors/async/async_function_depends_on_its_own_frame.zig index 4dde5860ba..b266d86ed8 100644 --- a/test/cases/compile_errors/async/async_function_depends_on_its_own_frame.zig +++ b/test/cases/compile_errors/async/async_function_depends_on_its_own_frame.zig @@ -3,7 +3,7 @@ export fn entry() void { } fn amain() callconv(.Async) void { var x: [@sizeOf(@Frame(amain))]u8 = undefined; - _ = x; + _ = &x; } // error diff --git a/test/cases/compile_errors/async/async_function_indirectly_depends_on_its_own_frame.zig b/test/cases/compile_errors/async/async_function_indirectly_depends_on_its_own_frame.zig index 4dac0d4fa3..4e7341bff5 100644 --- a/test/cases/compile_errors/async/async_function_indirectly_depends_on_its_own_frame.zig +++ b/test/cases/compile_errors/async/async_function_indirectly_depends_on_its_own_frame.zig @@ -6,7 +6,7 @@ fn amain() callconv(.Async) void { } fn other() void { var x: [@sizeOf(@Frame(amain))]u8 = undefined; - _ = x; + _ = &x; } // error diff --git a/test/cases/compile_errors/async/bad_alignment_in_asynccall.zig b/test/cases/compile_errors/async/bad_alignment_in_asynccall.zig index 3999140009..da00a0eeb7 100644 --- a/test/cases/compile_errors/async/bad_alignment_in_asynccall.zig +++ b/test/cases/compile_errors/async/bad_alignment_in_asynccall.zig @@ -2,6 +2,7 @@ export fn entry() void { var ptr: fn () callconv(.Async) void = func; var bytes: [64]u8 = undefined; _ = @asyncCall(&bytes, {}, ptr, .{}); + _ = &ptr; } fn func() callconv(.Async) void {} diff --git a/test/cases/compile_errors/async/const_frame_cast_to_anyframe.zig b/test/cases/compile_errors/async/const_frame_cast_to_anyframe.zig index affdb953d7..52b866afcf 100644 --- a/test/cases/compile_errors/async/const_frame_cast_to_anyframe.zig +++ b/test/cases/compile_errors/async/const_frame_cast_to_anyframe.zig @@ -5,7 +5,7 @@ export fn a() void { export fn b() void { const f = async func(); var x: anyframe = &f; - _ = x; + _ = &x; } fn func() void { suspend {} diff --git a/test/cases/compile_errors/async/indirect_recursion_of_async_functions_detected.zig b/test/cases/compile_errors/async/indirect_recursion_of_async_functions_detected.zig index d845dc7930..804baed45f 100644 --- a/test/cases/compile_errors/async/indirect_recursion_of_async_functions_detected.zig +++ b/test/cases/compile_errors/async/indirect_recursion_of_async_functions_detected.zig @@ -12,7 +12,7 @@ fn rangeSum(x: i32) i32 { frame = null; if (x == 0) return 0; - var child = rangeSumIndirect(x - 1); + const child = rangeSumIndirect(x - 1); return child + 1; } @@ -23,7 +23,7 @@ fn rangeSumIndirect(x: i32) i32 { frame = null; if (x == 0) return 0; - var child = rangeSum(x - 1); + const child = rangeSum(x - 1); return child + 1; } @@ -32,5 +32,5 @@ fn rangeSumIndirect(x: i32) i32 { // target=native // // tmp.zig:8:1: error: '@Frame(rangeSum)' depends on itself -// tmp.zig:15:33: note: when analyzing type '@Frame(rangeSum)' here -// tmp.zig:26:25: note: when analyzing type '@Frame(rangeSumIndirect)' here +// tmp.zig:15:35: note: when analyzing type '@Frame(rangeSum)' here +// tmp.zig:28:25: note: when analyzing type '@Frame(rangeSumIndirect)' here diff --git a/test/cases/compile_errors/async/invalid_suspend_in_exported_function.zig b/test/cases/compile_errors/async/invalid_suspend_in_exported_function.zig index cfcbfba889..fb3488ce95 100644 --- a/test/cases/compile_errors/async/invalid_suspend_in_exported_function.zig +++ b/test/cases/compile_errors/async/invalid_suspend_in_exported_function.zig @@ -1,7 +1,7 @@ export fn entry() void { var frame = async func(); var result = await frame; - _ = result; + _ = &result; } fn func() void { suspend {} diff --git a/test/cases/compile_errors/async/non_async_function_pointer_passed_to_asyncCall.zig b/test/cases/compile_errors/async/non_async_function_pointer_passed_to_asyncCall.zig index 97bc6a09bd..b62524f6de 100644 --- a/test/cases/compile_errors/async/non_async_function_pointer_passed_to_asyncCall.zig +++ b/test/cases/compile_errors/async/non_async_function_pointer_passed_to_asyncCall.zig @@ -2,6 +2,7 @@ export fn entry() void { var ptr = afunc; var bytes: [100]u8 align(16) = undefined; _ = @asyncCall(&bytes, {}, ptr, .{}); + _ = &ptr; } fn afunc() void {} diff --git a/test/cases/compile_errors/async/prevent_bad_implicit_casting_of_anyframe_types.zig b/test/cases/compile_errors/async/prevent_bad_implicit_casting_of_anyframe_types.zig index bdf7bec458..6ab99bf00d 100644 --- a/test/cases/compile_errors/async/prevent_bad_implicit_casting_of_anyframe_types.zig +++ b/test/cases/compile_errors/async/prevent_bad_implicit_casting_of_anyframe_types.zig @@ -1,17 +1,17 @@ export fn a() void { var x: anyframe = undefined; var y: anyframe->i32 = x; - _ = y; + _ = .{ &x, &y }; } export fn b() void { var x: i32 = undefined; var y: anyframe->i32 = x; - _ = y; + _ = .{ &x, &y }; } export fn c() void { var x: @Frame(func) = undefined; var y: anyframe->i32 = &x; - _ = y; + _ = .{ &x, &y }; } fn func() void {} diff --git a/test/cases/compile_errors/async/runtime-known_async_function_called.zig b/test/cases/compile_errors/async/runtime-known_async_function_called.zig index 90685ce566..8a5ef27d62 100644 --- a/test/cases/compile_errors/async/runtime-known_async_function_called.zig +++ b/test/cases/compile_errors/async/runtime-known_async_function_called.zig @@ -4,6 +4,7 @@ export fn entry() void { fn amain() void { var ptr = afunc; _ = ptr(); + _ = &ptr; } fn afunc() callconv(.Async) void {} diff --git a/test/cases/compile_errors/async/runtime-known_function_called_with_async_keyword.zig b/test/cases/compile_errors/async/runtime-known_function_called_with_async_keyword.zig index bfc22cca25..9933c95435 100644 --- a/test/cases/compile_errors/async/runtime-known_function_called_with_async_keyword.zig +++ b/test/cases/compile_errors/async/runtime-known_function_called_with_async_keyword.zig @@ -1,6 +1,7 @@ export fn entry() void { var ptr = afunc; _ = async ptr(); + _ = &ptr; } fn afunc() callconv(.Async) void {} |
