diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2023-06-24 16:58:19 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-06-24 16:58:19 -0700 |
| commit | 146b79af153bbd5dafda0ba12a040385c7fc58f8 (patch) | |
| tree | 67e3db8b444d65c667e314770fc983a7fc8ba293 /test/cases/compile_errors | |
| parent | 13853bef0df3c90633021850cc6d6abaeea03282 (diff) | |
| parent | 21ac0beb436f49fe49c6982a872f2dc48e4bea5e (diff) | |
| download | zig-146b79af153bbd5dafda0ba12a040385c7fc58f8.tar.gz zig-146b79af153bbd5dafda0ba12a040385c7fc58f8.zip | |
Merge pull request #16163 from mlugg/feat/builtins-infer-dest-ty
Infer destination type of cast builtins using result type
Diffstat (limited to 'test/cases/compile_errors')
49 files changed, 124 insertions, 119 deletions
diff --git a/test/cases/compile_errors/alignCast_expects_pointer_or_slice.zig b/test/cases/compile_errors/alignCast_expects_pointer_or_slice.zig index 1b8e3767b2..25345aced0 100644 --- a/test/cases/compile_errors/alignCast_expects_pointer_or_slice.zig +++ b/test/cases/compile_errors/alignCast_expects_pointer_or_slice.zig @@ -1,9 +1,10 @@ export fn entry() void { - @alignCast(4, @as(u32, 3)); + const x: *align(8) u32 = @alignCast(@as(u32, 3)); + _ = x; } // error // backend=stage2 // target=native // -// :2:19: error: expected pointer type, found 'u32' +// :2:41: error: expected pointer type, found 'u32' diff --git a/test/cases/compile_errors/bad_alignCast_at_comptime.zig b/test/cases/compile_errors/bad_alignCast_at_comptime.zig index 885700ecac..c870521822 100644 --- a/test/cases/compile_errors/bad_alignCast_at_comptime.zig +++ b/test/cases/compile_errors/bad_alignCast_at_comptime.zig @@ -1,6 +1,6 @@ comptime { - const ptr = @ptrFromInt(*align(1) i32, 0x1); - const aligned = @alignCast(4, ptr); + const ptr: *align(1) i32 = @ptrFromInt(0x1); + const aligned: *align(4) i32 = @alignCast(ptr); _ = aligned; } @@ -8,4 +8,4 @@ comptime { // backend=stage2 // target=native // -// :3:35: error: pointer address 0x1 is not aligned to 4 bytes +// :3:47: error: pointer address 0x1 is not aligned to 4 bytes diff --git a/test/cases/compile_errors/bitCast_same_size_but_bit_count_mismatch.zig b/test/cases/compile_errors/bitCast_same_size_but_bit_count_mismatch.zig index 2f7bd9c9bc..e366e0cb03 100644 --- a/test/cases/compile_errors/bitCast_same_size_but_bit_count_mismatch.zig +++ b/test/cases/compile_errors/bitCast_same_size_but_bit_count_mismatch.zig @@ -1,5 +1,5 @@ export fn entry(byte: u8) void { - var oops = @bitCast(u7, byte); + var oops: u7 = @bitCast(byte); _ = oops; } @@ -7,4 +7,4 @@ export fn entry(byte: u8) void { // backend=stage2 // target=native // -// :2:16: error: @bitCast size mismatch: destination type 'u7' has 7 bits but source type 'u8' has 8 bits +// :2:20: error: @bitCast size mismatch: destination type 'u7' has 7 bits but source type 'u8' has 8 bits diff --git a/test/cases/compile_errors/bitCast_to_enum_type.zig b/test/cases/compile_errors/bitCast_to_enum_type.zig index b3bc72c21b..7f3711b7f1 100644 --- a/test/cases/compile_errors/bitCast_to_enum_type.zig +++ b/test/cases/compile_errors/bitCast_to_enum_type.zig @@ -1,6 +1,6 @@ export fn entry() void { const E = enum(u32) { a, b }; - const y = @bitCast(E, @as(u32, 3)); + const y: E = @bitCast(@as(u32, 3)); _ = y; } @@ -8,5 +8,5 @@ export fn entry() void { // backend=stage2 // target=native // -// :3:24: error: cannot @bitCast to 'tmp.entry.E' -// :3:24: note: use @enumFromInt to cast from 'u32' +// :3:18: error: cannot @bitCast to 'tmp.entry.E' +// :3:18: note: use @enumFromInt to cast from 'u32' diff --git a/test/cases/compile_errors/bitCast_with_different_sizes_inside_an_expression.zig b/test/cases/compile_errors/bitCast_with_different_sizes_inside_an_expression.zig index bf87ba8bc5..f73dfeb38a 100644 --- a/test/cases/compile_errors/bitCast_with_different_sizes_inside_an_expression.zig +++ b/test/cases/compile_errors/bitCast_with_different_sizes_inside_an_expression.zig @@ -1,5 +1,5 @@ export fn entry() void { - var foo = (@bitCast(u8, @as(f32, 1.0)) == 0xf); + var foo = (@as(u8, @bitCast(@as(f32, 1.0))) == 0xf); _ = foo; } @@ -7,4 +7,4 @@ export fn entry() void { // backend=stage2 // target=native // -// :2:16: error: @bitCast size mismatch: destination type 'u8' has 8 bits but source type 'f32' has 32 bits +// :2:24: error: @bitCast size mismatch: destination type 'u8' has 8 bits but source type 'f32' has 32 bits diff --git a/test/cases/compile_errors/cast_negative_value_to_unsigned_integer.zig b/test/cases/compile_errors/cast_negative_value_to_unsigned_integer.zig index ebd9012015..57206b267f 100644 --- a/test/cases/compile_errors/cast_negative_value_to_unsigned_integer.zig +++ b/test/cases/compile_errors/cast_negative_value_to_unsigned_integer.zig @@ -1,6 +1,6 @@ comptime { const value: i32 = -1; - const unsigned = @intCast(u32, value); + const unsigned: u32 = @intCast(value); _ = unsigned; } export fn entry1() void { diff --git a/test/cases/compile_errors/compile_log_a_pointer_to_an_opaque_value.zig b/test/cases/compile_errors/compile_log_a_pointer_to_an_opaque_value.zig index 73de52fc97..4f79da9fb1 100644 --- a/test/cases/compile_errors/compile_log_a_pointer_to_an_opaque_value.zig +++ b/test/cases/compile_errors/compile_log_a_pointer_to_an_opaque_value.zig @@ -1,5 +1,5 @@ export fn entry() void { - @compileLog(@as(*align(1) const anyopaque, @ptrCast(*const anyopaque, &entry))); + @compileLog(@as(*const anyopaque, @ptrCast(&entry))); } // error diff --git a/test/cases/compile_errors/compile_time_null_ptr_cast.zig b/test/cases/compile_errors/compile_time_null_ptr_cast.zig index 25805e9f35..7d25931aaa 100644 --- a/test/cases/compile_errors/compile_time_null_ptr_cast.zig +++ b/test/cases/compile_errors/compile_time_null_ptr_cast.zig @@ -1,6 +1,6 @@ comptime { var opt_ptr: ?*i32 = null; - const ptr = @ptrCast(*i32, opt_ptr); + const ptr: *i32 = @ptrCast(opt_ptr); _ = ptr; } diff --git a/test/cases/compile_errors/compile_time_undef_ptr_cast.zig b/test/cases/compile_errors/compile_time_undef_ptr_cast.zig index 14edd293de..d93e8bc73d 100644 --- a/test/cases/compile_errors/compile_time_undef_ptr_cast.zig +++ b/test/cases/compile_errors/compile_time_undef_ptr_cast.zig @@ -1,6 +1,6 @@ comptime { var undef_ptr: *i32 = undefined; - const ptr = @ptrCast(*i32, undef_ptr); + const ptr: *i32 = @ptrCast(undef_ptr); _ = ptr; } diff --git a/test/cases/compile_errors/comptime_call_of_function_pointer.zig b/test/cases/compile_errors/comptime_call_of_function_pointer.zig index d6598aab39..574f55e9f3 100644 --- a/test/cases/compile_errors/comptime_call_of_function_pointer.zig +++ b/test/cases/compile_errors/comptime_call_of_function_pointer.zig @@ -1,5 +1,5 @@ export fn entry() void { - const fn_ptr = @ptrFromInt(*align(1) fn () void, 0xffd2); + const fn_ptr: *align(1) fn () void = @ptrFromInt(0xffd2); comptime fn_ptr(); } diff --git a/test/cases/compile_errors/comptime_slice-sentinel_does_not_match_memory_at_target_index_terminated.zig b/test/cases/compile_errors/comptime_slice-sentinel_does_not_match_memory_at_target_index_terminated.zig index ffa21af10a..83c48e8acd 100644 --- a/test/cases/compile_errors/comptime_slice-sentinel_does_not_match_memory_at_target_index_terminated.zig +++ b/test/cases/compile_errors/comptime_slice-sentinel_does_not_match_memory_at_target_index_terminated.zig @@ -24,7 +24,7 @@ export fn foo_vector_ConstPtrSpecialBaseArray() void { export fn foo_vector_ConstPtrSpecialRef() void { comptime { var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; - var target: [*]u8 = @ptrCast([*]u8, &buf); + var target: [*]u8 = @ptrCast(&buf); const slice = target[0..3 :0]; _ = slice; } @@ -40,7 +40,7 @@ export fn foo_cvector_ConstPtrSpecialBaseArray() void { export fn foo_cvector_ConstPtrSpecialRef() void { comptime { var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; - var target: [*c]u8 = @ptrCast([*c]u8, &buf); + var target: [*c]u8 = @ptrCast(&buf); const slice = target[0..3 :0]; _ = slice; } diff --git a/test/cases/compile_errors/comptime_slice-sentinel_does_not_match_memory_at_target_index_unterminated.zig b/test/cases/compile_errors/comptime_slice-sentinel_does_not_match_memory_at_target_index_unterminated.zig index c5bb2d9643..c111b026a5 100644 --- a/test/cases/compile_errors/comptime_slice-sentinel_does_not_match_memory_at_target_index_unterminated.zig +++ b/test/cases/compile_errors/comptime_slice-sentinel_does_not_match_memory_at_target_index_unterminated.zig @@ -24,7 +24,7 @@ export fn foo_vector_ConstPtrSpecialBaseArray() void { export fn foo_vector_ConstPtrSpecialRef() void { comptime { var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; - var target: [*]u8 = @ptrCast([*]u8, &buf); + var target: [*]u8 = @ptrCast(&buf); const slice = target[0..3 :0]; _ = slice; } @@ -40,7 +40,7 @@ export fn foo_cvector_ConstPtrSpecialBaseArray() void { export fn foo_cvector_ConstPtrSpecialRef() void { comptime { var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; - var target: [*c]u8 = @ptrCast([*c]u8, &buf); + var target: [*c]u8 = @ptrCast(&buf); const slice = target[0..3 :0]; _ = slice; } diff --git a/test/cases/compile_errors/comptime_slice-sentinel_does_not_match_target-sentinel.zig b/test/cases/compile_errors/comptime_slice-sentinel_does_not_match_target-sentinel.zig index aa52fb9756..24aa36949b 100644 --- a/test/cases/compile_errors/comptime_slice-sentinel_does_not_match_target-sentinel.zig +++ b/test/cases/compile_errors/comptime_slice-sentinel_does_not_match_target-sentinel.zig @@ -24,7 +24,7 @@ export fn foo_vector_ConstPtrSpecialBaseArray() void { export fn foo_vector_ConstPtrSpecialRef() void { comptime { var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; - var target: [*]u8 = @ptrCast([*]u8, &buf); + var target: [*]u8 = @ptrCast(&buf); const slice = target[0..14 :255]; _ = slice; } @@ -40,7 +40,7 @@ export fn foo_cvector_ConstPtrSpecialBaseArray() void { export fn foo_cvector_ConstPtrSpecialRef() void { comptime { var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; - var target: [*c]u8 = @ptrCast([*c]u8, &buf); + var target: [*c]u8 = @ptrCast(&buf); const slice = target[0..14 :255]; _ = slice; } diff --git a/test/cases/compile_errors/comptime_slice-sentinel_is_out_of_bounds_terminated.zig b/test/cases/compile_errors/comptime_slice-sentinel_is_out_of_bounds_terminated.zig index 86bd4ce8bb..249d59414a 100644 --- a/test/cases/compile_errors/comptime_slice-sentinel_is_out_of_bounds_terminated.zig +++ b/test/cases/compile_errors/comptime_slice-sentinel_is_out_of_bounds_terminated.zig @@ -24,7 +24,7 @@ export fn foo_vector_ConstPtrSpecialBaseArray() void { export fn foo_vector_ConstPtrSpecialRef() void { comptime { var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; - var target: [*]u8 = @ptrCast([*]u8, &buf); + var target: [*]u8 = @ptrCast(&buf); const slice = target[0..15 :0]; _ = slice; } @@ -40,7 +40,7 @@ export fn foo_cvector_ConstPtrSpecialBaseArray() void { export fn foo_cvector_ConstPtrSpecialRef() void { comptime { var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; - var target: [*c]u8 = @ptrCast([*c]u8, &buf); + var target: [*c]u8 = @ptrCast(&buf); const slice = target[0..15 :0]; _ = slice; } diff --git a/test/cases/compile_errors/comptime_slice-sentinel_is_out_of_bounds_unterminated.zig b/test/cases/compile_errors/comptime_slice-sentinel_is_out_of_bounds_unterminated.zig index e1b8a5bc2d..a6e599ca38 100644 --- a/test/cases/compile_errors/comptime_slice-sentinel_is_out_of_bounds_unterminated.zig +++ b/test/cases/compile_errors/comptime_slice-sentinel_is_out_of_bounds_unterminated.zig @@ -24,7 +24,7 @@ export fn foo_vector_ConstPtrSpecialBaseArray() void { export fn foo_vector_ConstPtrSpecialRef() void { comptime { var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; - var target: [*]u8 = @ptrCast([*]u8, &buf); + var target: [*]u8 = @ptrCast(&buf); const slice = target[0..14 :0]; _ = slice; } @@ -40,7 +40,7 @@ export fn foo_cvector_ConstPtrSpecialBaseArray() void { export fn foo_cvector_ConstPtrSpecialRef() void { comptime { var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; - var target: [*c]u8 = @ptrCast([*c]u8, &buf); + var target: [*c]u8 = @ptrCast(&buf); const slice = target[0..14 :0]; _ = slice; } diff --git a/test/cases/compile_errors/enumFromInt_on_non-exhaustive_enums_checks_int_in_range.zig b/test/cases/compile_errors/enumFromInt_on_non-exhaustive_enums_checks_int_in_range.zig index dfef66b628..112017d29d 100644 --- a/test/cases/compile_errors/enumFromInt_on_non-exhaustive_enums_checks_int_in_range.zig +++ b/test/cases/compile_errors/enumFromInt_on_non-exhaustive_enums_checks_int_in_range.zig @@ -1,11 +1,11 @@ pub export fn entry() void { const E = enum(u3) { a, b, c, _ }; - @compileLog(@enumFromInt(E, 100)); + @compileLog(@as(E, @enumFromInt(100))); } // error // target=native // backend=stage2 // -// :3:17: error: int value '100' out of range of non-exhaustive enum 'tmp.entry.E' +// :3:24: error: int value '100' out of range of non-exhaustive enum 'tmp.entry.E' // :2:15: note: enum declared here diff --git a/test/cases/compile_errors/enum_in_field_count_range_but_not_matching_tag.zig b/test/cases/compile_errors/enum_in_field_count_range_but_not_matching_tag.zig index 0cf9fcce01..3e1190cc32 100644 --- a/test/cases/compile_errors/enum_in_field_count_range_but_not_matching_tag.zig +++ b/test/cases/compile_errors/enum_in_field_count_range_but_not_matching_tag.zig @@ -3,7 +3,7 @@ const Foo = enum(u32) { B = 11, }; export fn entry() void { - var x = @enumFromInt(Foo, 0); + var x: Foo = @enumFromInt(0); _ = x; } @@ -11,5 +11,5 @@ export fn entry() void { // backend=stage2 // target=native // -// :6:13: error: enum 'tmp.Foo' has no tag with value '0' +// :6:18: error: enum 'tmp.Foo' has no tag with value '0' // :1:13: note: enum declared here diff --git a/test/cases/compile_errors/explicit_error_set_cast_known_at_comptime_violates_error_sets.zig b/test/cases/compile_errors/explicit_error_set_cast_known_at_comptime_violates_error_sets.zig index a3af883198..cfb01c3ddc 100644 --- a/test/cases/compile_errors/explicit_error_set_cast_known_at_comptime_violates_error_sets.zig +++ b/test/cases/compile_errors/explicit_error_set_cast_known_at_comptime_violates_error_sets.zig @@ -2,7 +2,7 @@ const Set1 = error{ A, B }; const Set2 = error{ A, C }; comptime { var x = Set1.B; - var y = @errSetCast(Set2, x); + var y: Set2 = @errSetCast(x); _ = y; } @@ -10,4 +10,4 @@ comptime { // backend=stage2 // target=native // -// :5:13: error: 'error.B' not a member of error set 'error{C,A}' +// :5:19: error: 'error.B' not a member of error set 'error{C,A}' diff --git a/test/cases/compile_errors/explicitly_casting_non_tag_type_to_enum.zig b/test/cases/compile_errors/explicitly_casting_non_tag_type_to_enum.zig index 6ae39489a0..bb920138e1 100644 --- a/test/cases/compile_errors/explicitly_casting_non_tag_type_to_enum.zig +++ b/test/cases/compile_errors/explicitly_casting_non_tag_type_to_enum.zig @@ -7,7 +7,7 @@ const Small = enum(u2) { export fn entry() void { var y = @as(f32, 3); - var x = @enumFromInt(Small, y); + var x: Small = @enumFromInt(y); _ = x; } diff --git a/test/cases/compile_errors/fieldParentPtr-comptime_field_ptr_not_based_on_struct.zig b/test/cases/compile_errors/fieldParentPtr-comptime_field_ptr_not_based_on_struct.zig index 9fc8038d7a..2147fb8aed 100644 --- a/test/cases/compile_errors/fieldParentPtr-comptime_field_ptr_not_based_on_struct.zig +++ b/test/cases/compile_errors/fieldParentPtr-comptime_field_ptr_not_based_on_struct.zig @@ -8,7 +8,7 @@ const foo = Foo{ }; comptime { - const field_ptr = @ptrFromInt(*i32, 0x1234); + const field_ptr: *i32 = @ptrFromInt(0x1234); const another_foo_ptr = @fieldParentPtr(Foo, "b", field_ptr); _ = another_foo_ptr; } diff --git a/test/cases/compile_errors/field_access_of_opaque_type.zig b/test/cases/compile_errors/field_access_of_opaque_type.zig index f9ec483305..7f975c4b0a 100644 --- a/test/cases/compile_errors/field_access_of_opaque_type.zig +++ b/test/cases/compile_errors/field_access_of_opaque_type.zig @@ -2,7 +2,7 @@ const MyType = opaque {}; export fn entry() bool { var x: i32 = 1; - return bar(@ptrCast(*MyType, &x)); + return bar(@ptrCast(&x)); } fn bar(x: *MyType) bool { diff --git a/test/cases/compile_errors/incorrect_type_to_memset_memcpy.zig b/test/cases/compile_errors/incorrect_type_to_memset_memcpy.zig index 44405b3c20..55af9c1185 100644 --- a/test/cases/compile_errors/incorrect_type_to_memset_memcpy.zig +++ b/test/cases/compile_errors/incorrect_type_to_memset_memcpy.zig @@ -2,7 +2,7 @@ pub export fn entry() void { var buf: [5]u8 = .{ 1, 2, 3, 4, 5 }; var slice: []u8 = &buf; const a: u32 = 1234; - @memcpy(slice.ptr, @ptrCast([*]const u8, &a)); + @memcpy(slice.ptr, @as([*]const u8, @ptrCast(&a))); } pub export fn entry1() void { var buf: [5]u8 = .{ 1, 2, 3, 4, 5 }; @@ -39,7 +39,7 @@ pub export fn memset_array() void { // // :5:5: error: unknown @memcpy length // :5:18: note: destination type '[*]u8' provides no length -// :5:24: note: source type '[*]align(4) const u8' provides no length +// :5:24: note: source type '[*]const u8' provides no length // :10:13: error: type '*u8' is not an indexable pointer // :10:13: note: operand must be a slice, a many pointer or a pointer to an array // :15:13: error: type '*u8' is not an indexable pointer diff --git a/test/cases/compile_errors/increase_pointer_alignment_in_ptrCast.zig b/test/cases/compile_errors/increase_pointer_alignment_in_ptrCast.zig index 8d7e14acae..22bd90b068 100644 --- a/test/cases/compile_errors/increase_pointer_alignment_in_ptrCast.zig +++ b/test/cases/compile_errors/increase_pointer_alignment_in_ptrCast.zig @@ -1,6 +1,6 @@ export fn entry() u32 { var bytes: [4]u8 = [_]u8{ 0x01, 0x02, 0x03, 0x04 }; - const ptr = @ptrCast(*u32, &bytes[0]); + const ptr: *u32 = @ptrCast(&bytes[0]); return ptr.*; } @@ -8,7 +8,7 @@ export fn entry() u32 { // backend=stage2 // target=native // -// :3:17: error: cast increases pointer alignment +// :3:23: error: cast increases pointer alignment // :3:32: note: '*u8' has alignment '1' -// :3:26: note: '*u32' has alignment '4' -// :3:17: note: consider using '@alignCast' +// :3:23: note: '*u32' has alignment '4' +// :3:23: note: use @alignCast to assert pointer alignment diff --git a/test/cases/compile_errors/int-float_conversion_to_comptime_int-float.zig b/test/cases/compile_errors/int-float_conversion_to_comptime_int-float.zig index ecf8f61fc5..7724632069 100644 --- a/test/cases/compile_errors/int-float_conversion_to_comptime_int-float.zig +++ b/test/cases/compile_errors/int-float_conversion_to_comptime_int-float.zig @@ -1,17 +1,17 @@ export fn foo() void { var a: f32 = 2; - _ = @intFromFloat(comptime_int, a); + _ = @as(comptime_int, @intFromFloat(a)); } export fn bar() void { var a: u32 = 2; - _ = @floatFromInt(comptime_float, a); + _ = @as(comptime_float, @floatFromInt(a)); } // error // backend=stage2 // target=native // -// :3:37: error: unable to resolve comptime value -// :3:37: note: value being casted to 'comptime_int' must be comptime-known -// :7:39: error: unable to resolve comptime value -// :7:39: note: value being casted to 'comptime_float' must be comptime-known +// :3:41: error: unable to resolve comptime value +// :3:41: note: value being casted to 'comptime_int' must be comptime-known +// :7:43: error: unable to resolve comptime value +// :7:43: note: value being casted to 'comptime_float' must be comptime-known diff --git a/test/cases/compile_errors/intFromFloat_comptime_safety.zig b/test/cases/compile_errors/intFromFloat_comptime_safety.zig index 275f67006f..e3bfc3eb96 100644 --- a/test/cases/compile_errors/intFromFloat_comptime_safety.zig +++ b/test/cases/compile_errors/intFromFloat_comptime_safety.zig @@ -1,17 +1,17 @@ comptime { - _ = @intFromFloat(i8, @as(f32, -129.1)); + _ = @as(i8, @intFromFloat(@as(f32, -129.1))); } comptime { - _ = @intFromFloat(u8, @as(f32, -1.1)); + _ = @as(u8, @intFromFloat(@as(f32, -1.1))); } comptime { - _ = @intFromFloat(u8, @as(f32, 256.1)); + _ = @as(u8, @intFromFloat(@as(f32, 256.1))); } // error // backend=stage2 // target=native // -// :2:27: error: float value '-129.10000610351562' cannot be stored in integer type 'i8' -// :5:27: error: float value '-1.100000023841858' cannot be stored in integer type 'u8' -// :8:27: error: float value '256.1000061035156' cannot be stored in integer type 'u8' +// :2:31: error: float value '-129.10000610351562' cannot be stored in integer type 'i8' +// :5:31: error: float value '-1.100000023841858' cannot be stored in integer type 'u8' +// :8:31: error: float value '256.1000061035156' cannot be stored in integer type 'u8' diff --git a/test/cases/compile_errors/intFromPtr_0_to_non_optional_pointer.zig b/test/cases/compile_errors/intFromPtr_0_to_non_optional_pointer.zig index 4a2ea05eaa..e443b3daa9 100644 --- a/test/cases/compile_errors/intFromPtr_0_to_non_optional_pointer.zig +++ b/test/cases/compile_errors/intFromPtr_0_to_non_optional_pointer.zig @@ -1,5 +1,5 @@ export fn entry() void { - var b = @ptrFromInt(*i32, 0); + var b: *i32 = @ptrFromInt(0); _ = b; } diff --git a/test/cases/compile_errors/int_to_err_non_global_invalid_number.zig b/test/cases/compile_errors/int_to_err_non_global_invalid_number.zig index 6a1f2db531..32f4657ed5 100644 --- a/test/cases/compile_errors/int_to_err_non_global_invalid_number.zig +++ b/test/cases/compile_errors/int_to_err_non_global_invalid_number.zig @@ -8,7 +8,7 @@ const Set2 = error{ }; comptime { var x = @intFromError(Set1.B); - var y = @errSetCast(Set2, @errorFromInt(x)); + var y: Set2 = @errSetCast(@errorFromInt(x)); _ = y; } @@ -16,4 +16,4 @@ comptime { // backend=llvm // target=native // -// :11:13: error: 'error.B' not a member of error set 'error{C,A}' +// :11:19: error: 'error.B' not a member of error set 'error{C,A}' diff --git a/test/cases/compile_errors/integer_cast_truncates_bits.zig b/test/cases/compile_errors/integer_cast_truncates_bits.zig index 82eb6b61cf..a230dd3e5b 100644 --- a/test/cases/compile_errors/integer_cast_truncates_bits.zig +++ b/test/cases/compile_errors/integer_cast_truncates_bits.zig @@ -1,6 +1,6 @@ export fn entry1() void { const spartan_count: u16 = 300; - const byte = @intCast(u8, spartan_count); + const byte: u8 = @intCast(spartan_count); _ = byte; } export fn entry2() void { diff --git a/test/cases/compile_errors/integer_underflow_error.zig b/test/cases/compile_errors/integer_underflow_error.zig index 275b593ecc..49f46ee558 100644 --- a/test/cases/compile_errors/integer_underflow_error.zig +++ b/test/cases/compile_errors/integer_underflow_error.zig @@ -1,9 +1,9 @@ export fn entry() void { - _ = @ptrFromInt(*anyopaque, ~@as(usize, @import("std").math.maxInt(usize)) - 1); + _ = @as(*anyopaque, @ptrFromInt(~@as(usize, @import("std").math.maxInt(usize)) - 1)); } // error // backend=stage2 // target=native // -// :2:80: error: overflow of integer type 'usize' with value '-1' +// :2:84: error: overflow of integer type 'usize' with value '-1' diff --git a/test/cases/compile_errors/invalid_float_casts.zig b/test/cases/compile_errors/invalid_float_casts.zig index 507ced1e57..789eb10976 100644 --- a/test/cases/compile_errors/invalid_float_casts.zig +++ b/test/cases/compile_errors/invalid_float_casts.zig @@ -1,25 +1,25 @@ export fn foo() void { var a: f32 = 2; - _ = @floatCast(comptime_float, a); + _ = @as(comptime_float, @floatCast(a)); } export fn bar() void { var a: f32 = 2; - _ = @intFromFloat(f32, a); + _ = @as(f32, @intFromFloat(a)); } export fn baz() void { var a: f32 = 2; - _ = @floatFromInt(f32, a); + _ = @as(f32, @floatFromInt(a)); } export fn qux() void { var a: u32 = 2; - _ = @floatCast(f32, a); + _ = @as(f32, @floatCast(a)); } // error // backend=stage2 // target=native // -// :3:36: error: unable to cast runtime value to 'comptime_float' -// :7:23: error: expected integer type, found 'f32' -// :11:28: error: expected integer type, found 'f32' -// :15:25: error: expected float type, found 'u32' +// :3:40: error: unable to cast runtime value to 'comptime_float' +// :7:18: error: expected integer type, found 'f32' +// :11:32: error: expected integer type, found 'f32' +// :15:29: error: expected float type, found 'u32' diff --git a/test/cases/compile_errors/invalid_int_casts.zig b/test/cases/compile_errors/invalid_int_casts.zig index 262a096bd9..1e52c52609 100644 --- a/test/cases/compile_errors/invalid_int_casts.zig +++ b/test/cases/compile_errors/invalid_int_casts.zig @@ -1,25 +1,25 @@ export fn foo() void { var a: u32 = 2; - _ = @intCast(comptime_int, a); + _ = @as(comptime_int, @intCast(a)); } export fn bar() void { var a: u32 = 2; - _ = @floatFromInt(u32, a); + _ = @as(u32, @floatFromInt(a)); } export fn baz() void { var a: u32 = 2; - _ = @intFromFloat(u32, a); + _ = @as(u32, @intFromFloat(a)); } export fn qux() void { var a: f32 = 2; - _ = @intCast(u32, a); + _ = @as(u32, @intCast(a)); } // error // backend=stage2 // target=native // -// :3:32: error: unable to cast runtime value to 'comptime_int' -// :7:23: error: expected float type, found 'u32' -// :11:28: error: expected float type, found 'u32' -// :15:23: error: expected integer or vector, found 'f32' +// :3:36: error: unable to cast runtime value to 'comptime_int' +// :7:18: error: expected float type, found 'u32' +// :11:32: error: expected float type, found 'u32' +// :15:27: error: expected integer or vector, found 'f32' diff --git a/test/cases/compile_errors/invalid_non-exhaustive_enum_to_union.zig b/test/cases/compile_errors/invalid_non-exhaustive_enum_to_union.zig index 5457a61d3f..d7a93edfcd 100644 --- a/test/cases/compile_errors/invalid_non-exhaustive_enum_to_union.zig +++ b/test/cases/compile_errors/invalid_non-exhaustive_enum_to_union.zig @@ -8,12 +8,12 @@ const U = union(E) { b, }; export fn foo() void { - var e = @enumFromInt(E, 15); + var e: E = @enumFromInt(15); var u: U = e; _ = u; } export fn bar() void { - const e = @enumFromInt(E, 15); + const e: E = @enumFromInt(15); var u: U = e; _ = u; } @@ -24,5 +24,5 @@ export fn bar() void { // // :12:16: error: runtime coercion to union 'tmp.U' from non-exhaustive enum // :1:11: note: enum declared here -// :17:16: error: union 'tmp.U' has no tag with value '@enumFromInt(tmp.E, 15)' +// :17:16: error: union 'tmp.U' has no tag with value '@enumFromInt(15)' // :6:11: note: union declared here diff --git a/test/cases/compile_errors/issue_3818_bitcast_from_parray-slice_to_u16.zig b/test/cases/compile_errors/issue_3818_bitcast_from_parray-slice_to_u16.zig index 7a4c0eb7e8..c6566bb46a 100644 --- a/test/cases/compile_errors/issue_3818_bitcast_from_parray-slice_to_u16.zig +++ b/test/cases/compile_errors/issue_3818_bitcast_from_parray-slice_to_u16.zig @@ -1,11 +1,11 @@ export fn foo1() void { var bytes = [_]u8{ 1, 2 }; - const word: u16 = @bitCast(u16, bytes[0..]); + const word: u16 = @bitCast(bytes[0..]); _ = word; } export fn foo2() void { var bytes: []const u8 = &[_]u8{ 1, 2 }; - const word: u16 = @bitCast(u16, bytes); + const word: u16 = @bitCast(bytes); _ = word; } @@ -13,7 +13,7 @@ export fn foo2() void { // backend=stage2 // target=native // -// :3:42: error: cannot @bitCast from '*[2]u8' -// :3:42: note: use @intFromPtr to cast to 'u16' -// :8:37: error: cannot @bitCast from '[]const u8' -// :8:37: note: use @intFromPtr to cast to 'u16' +// :3:37: error: cannot @bitCast from '*[2]u8' +// :3:37: note: use @intFromPtr to cast to 'u16' +// :8:32: error: cannot @bitCast from '[]const u8' +// :8:32: note: use @intFromPtr to cast to 'u16' diff --git a/test/cases/compile_errors/load_too_many_bytes_from_comptime_reinterpreted_pointer.zig b/test/cases/compile_errors/load_too_many_bytes_from_comptime_reinterpreted_pointer.zig index baeb3e8c82..e4952e6951 100644 --- a/test/cases/compile_errors/load_too_many_bytes_from_comptime_reinterpreted_pointer.zig +++ b/test/cases/compile_errors/load_too_many_bytes_from_comptime_reinterpreted_pointer.zig @@ -1,7 +1,7 @@ export fn entry() void { const float: f32 align(@alignOf(i64)) = 5.99999999999994648725e-01; const float_ptr = &float; - const int_ptr = @ptrCast(*const i64, float_ptr); + const int_ptr: *const i64 = @ptrCast(float_ptr); const int_val = int_ptr.*; _ = int_val; } diff --git a/test/cases/compile_errors/missing_builtin_arg_in_initializer.zig b/test/cases/compile_errors/missing_builtin_arg_in_initializer.zig index 0bada117b2..cdbebf5457 100644 --- a/test/cases/compile_errors/missing_builtin_arg_in_initializer.zig +++ b/test/cases/compile_errors/missing_builtin_arg_in_initializer.zig @@ -1,8 +1,11 @@ comptime { - const v = @as(); + const a = @as(); } comptime { - const u = @bitCast(u32); + const b = @bitCast(); +} +comptime { + const c = @as(u32); } // error @@ -10,4 +13,5 @@ comptime { // target=native // // :2:15: error: expected 2 arguments, found 0 -// :5:15: error: expected 2 arguments, found 1 +// :5:15: error: expected 1 argument, found 0 +// :8:15: error: expected 2 arguments, found 1 diff --git a/test/cases/compile_errors/non_float_passed_to_intFromFloat.zig b/test/cases/compile_errors/non_float_passed_to_intFromFloat.zig index fac51c59c8..ee0b5e733e 100644 --- a/test/cases/compile_errors/non_float_passed_to_intFromFloat.zig +++ b/test/cases/compile_errors/non_float_passed_to_intFromFloat.zig @@ -1,5 +1,5 @@ export fn entry() void { - const x = @intFromFloat(i32, @as(i32, 54)); + const x: i32 = @intFromFloat(@as(i32, 54)); _ = x; } diff --git a/test/cases/compile_errors/non_int_passed_to_floatFromInt.zig b/test/cases/compile_errors/non_int_passed_to_floatFromInt.zig index 63e6753a53..c60842e980 100644 --- a/test/cases/compile_errors/non_int_passed_to_floatFromInt.zig +++ b/test/cases/compile_errors/non_int_passed_to_floatFromInt.zig @@ -1,5 +1,5 @@ export fn entry() void { - const x = @floatFromInt(f32, 1.1); + const x: f32 = @floatFromInt(1.1); _ = x; } diff --git a/test/cases/compile_errors/out_of_int_range_comptime_float_passed_to_intFromFloat.zig b/test/cases/compile_errors/out_of_int_range_comptime_float_passed_to_intFromFloat.zig index 574ffc5a20..d9cfd4b2de 100644 --- a/test/cases/compile_errors/out_of_int_range_comptime_float_passed_to_intFromFloat.zig +++ b/test/cases/compile_errors/out_of_int_range_comptime_float_passed_to_intFromFloat.zig @@ -1,5 +1,5 @@ export fn entry() void { - const x = @intFromFloat(i8, 200); + const x: i8 = @intFromFloat(200); _ = x; } diff --git a/test/cases/compile_errors/ptrCast_discards_const_qualifier.zig b/test/cases/compile_errors/ptrCast_discards_const_qualifier.zig index f27f5f4f93..a704ea456b 100644 --- a/test/cases/compile_errors/ptrCast_discards_const_qualifier.zig +++ b/test/cases/compile_errors/ptrCast_discards_const_qualifier.zig @@ -1,6 +1,6 @@ export fn entry() void { const x: i32 = 1234; - const y = @ptrCast(*i32, &x); + const y: *i32 = @ptrCast(&x); _ = y; } @@ -8,5 +8,5 @@ export fn entry() void { // backend=stage2 // target=native // -// :3:15: error: cast discards const qualifier -// :3:15: note: consider using '@constCast' +// :3:21: error: cast discards const qualifier +// :3:21: note: use @constCast to discard const qualifier diff --git a/test/cases/compile_errors/ptrFromInt_non_ptr_type.zig b/test/cases/compile_errors/ptrFromInt_non_ptr_type.zig index f472789aff..c75ceb444b 100644 --- a/test/cases/compile_errors/ptrFromInt_non_ptr_type.zig +++ b/test/cases/compile_errors/ptrFromInt_non_ptr_type.zig @@ -1,15 +1,15 @@ pub export fn entry() void { - _ = @ptrFromInt(i32, 10); + _ = @as(i32, @ptrFromInt(10)); } pub export fn entry2() void { - _ = @ptrFromInt([]u8, 20); + _ = @as([]u8, @ptrFromInt(20)); } // error // backend=stage2 // target=native // -// :2:21: error: expected pointer type, found 'i32' -// :6:21: error: integer cannot be converted to slice type '[]u8' -// :6:21: note: slice length cannot be inferred from address +// :2:18: error: expected pointer type, found 'i32' +// :6:19: error: integer cannot be converted to slice type '[]u8' +// :6:19: note: slice length cannot be inferred from address diff --git a/test/cases/compile_errors/ptrFromInt_with_misaligned_address.zig b/test/cases/compile_errors/ptrFromInt_with_misaligned_address.zig index c45e998d82..dfcbf6849c 100644 --- a/test/cases/compile_errors/ptrFromInt_with_misaligned_address.zig +++ b/test/cases/compile_errors/ptrFromInt_with_misaligned_address.zig @@ -1,5 +1,5 @@ pub export fn entry() void { - var y = @ptrFromInt([*]align(4) u8, 5); + var y: [*]align(4) u8 = @ptrFromInt(5); _ = y; } diff --git a/test/cases/compile_errors/ptrcast_to_non-pointer.zig b/test/cases/compile_errors/ptrcast_to_non-pointer.zig index 66a11a602b..ec93dc12c2 100644 --- a/test/cases/compile_errors/ptrcast_to_non-pointer.zig +++ b/test/cases/compile_errors/ptrcast_to_non-pointer.zig @@ -1,9 +1,9 @@ export fn entry(a: *i32) usize { - return @ptrCast(usize, a); + return @ptrCast(a); } // error // backend=llvm // target=native // -// :2:21: error: expected pointer type, found 'usize' +// :2:12: error: expected pointer type, found 'usize' diff --git a/test/cases/compile_errors/reading_past_end_of_pointer_casted_array.zig b/test/cases/compile_errors/reading_past_end_of_pointer_casted_array.zig index d3d9b03ff5..b06b541984 100644 --- a/test/cases/compile_errors/reading_past_end_of_pointer_casted_array.zig +++ b/test/cases/compile_errors/reading_past_end_of_pointer_casted_array.zig @@ -1,7 +1,7 @@ comptime { const array: [4]u8 = "aoeu".*; const sub_array = array[1..]; - const int_ptr = @ptrCast(*const u24, @alignCast(@alignOf(u24), sub_array)); + const int_ptr: *const u24 = @ptrCast(@alignCast(sub_array)); const deref = int_ptr.*; _ = deref; } diff --git a/test/cases/compile_errors/reify_type_for_exhaustive_enum_with_non-integer_tag_type.zig b/test/cases/compile_errors/reify_type_for_exhaustive_enum_with_non-integer_tag_type.zig index 9b140a0923..b26ec70296 100644 --- a/test/cases/compile_errors/reify_type_for_exhaustive_enum_with_non-integer_tag_type.zig +++ b/test/cases/compile_errors/reify_type_for_exhaustive_enum_with_non-integer_tag_type.zig @@ -7,7 +7,7 @@ const Tag = @Type(.{ }, }); export fn entry() void { - _ = @enumFromInt(Tag, 0); + _ = @as(Tag, @enumFromInt(0)); } // error diff --git a/test/cases/compile_errors/reify_type_for_exhaustive_enum_with_undefined_tag_type.zig b/test/cases/compile_errors/reify_type_for_exhaustive_enum_with_undefined_tag_type.zig index b2cd8e1214..5d5294ba30 100644 --- a/test/cases/compile_errors/reify_type_for_exhaustive_enum_with_undefined_tag_type.zig +++ b/test/cases/compile_errors/reify_type_for_exhaustive_enum_with_undefined_tag_type.zig @@ -7,7 +7,7 @@ const Tag = @Type(.{ }, }); export fn entry() void { - _ = @enumFromInt(Tag, 0); + _ = @as(Tag, @enumFromInt(0)); } // error diff --git a/test/cases/compile_errors/slice_cannot_have_its_bytes_reinterpreted.zig b/test/cases/compile_errors/slice_cannot_have_its_bytes_reinterpreted.zig index 5fab9c90a9..85fb0065d1 100644 --- a/test/cases/compile_errors/slice_cannot_have_its_bytes_reinterpreted.zig +++ b/test/cases/compile_errors/slice_cannot_have_its_bytes_reinterpreted.zig @@ -1,6 +1,6 @@ export fn foo() void { const bytes align(@alignOf([]const u8)) = [1]u8{0xfa} ** 16; - var value = @ptrCast(*const []const u8, &bytes).*; + var value = @as(*const []const u8, @ptrCast(&bytes)).*; _ = value; } @@ -8,4 +8,4 @@ export fn foo() void { // backend=stage2 // target=native // -// :3:52: error: comptime dereference requires '[]const u8' to have a well-defined layout, but it does not. +// :3:57: error: comptime dereference requires '[]const u8' to have a well-defined layout, but it does not. diff --git a/test/cases/compile_errors/tagName_on_invalid_value_of_non-exhaustive_enum.zig b/test/cases/compile_errors/tagName_on_invalid_value_of_non-exhaustive_enum.zig index df454a38d0..2b45fb6076 100644 --- a/test/cases/compile_errors/tagName_on_invalid_value_of_non-exhaustive_enum.zig +++ b/test/cases/compile_errors/tagName_on_invalid_value_of_non-exhaustive_enum.zig @@ -1,6 +1,6 @@ test "enum" { const E = enum(u8) { A, B, _ }; - _ = @tagName(@enumFromInt(E, 5)); + _ = @tagName(@as(E, @enumFromInt(5))); } // error @@ -8,5 +8,5 @@ test "enum" { // target=native // is_test=1 // -// :3:9: error: no field with value '@enumFromInt(tmp.test.enum.E, 5)' in enum 'test.enum.E' +// :3:9: error: no field with value '@enumFromInt(5)' in enum 'test.enum.E' // :2:15: note: declared here diff --git a/test/cases/compile_errors/truncate_sign_mismatch.zig b/test/cases/compile_errors/truncate_sign_mismatch.zig index a05660e28c..b34dfa8e07 100644 --- a/test/cases/compile_errors/truncate_sign_mismatch.zig +++ b/test/cases/compile_errors/truncate_sign_mismatch.zig @@ -1,25 +1,25 @@ export fn entry1() i8 { var x: u32 = 10; - return @truncate(i8, x); + return @truncate(x); } export fn entry2() u8 { var x: i32 = -10; - return @truncate(u8, x); + return @truncate(x); } export fn entry3() i8 { comptime var x: u32 = 10; - return @truncate(i8, x); + return @truncate(x); } export fn entry4() u8 { comptime var x: i32 = -10; - return @truncate(u8, x); + return @truncate(x); } // error // backend=stage2 // target=native // -// :3:26: error: expected signed integer type, found 'u32' -// :7:26: error: expected unsigned integer type, found 'i32' -// :11:26: error: expected signed integer type, found 'u32' -// :15:26: error: expected unsigned integer type, found 'i32' +// :3:22: error: expected signed integer type, found 'u32' +// :7:22: error: expected unsigned integer type, found 'i32' +// :11:22: error: expected signed integer type, found 'u32' +// :15:22: error: expected unsigned integer type, found 'i32' diff --git a/test/cases/compile_errors/wrong_pointer_coerced_to_pointer_to_opaque_{}.zig b/test/cases/compile_errors/wrong_pointer_coerced_to_pointer_to_opaque_{}.zig index a050eb6a4c..a7c8f0eb72 100644 --- a/test/cases/compile_errors/wrong_pointer_coerced_to_pointer_to_opaque_{}.zig +++ b/test/cases/compile_errors/wrong_pointer_coerced_to_pointer_to_opaque_{}.zig @@ -2,7 +2,7 @@ const Derp = opaque {}; extern fn bar(d: *Derp) void; export fn foo() void { var x = @as(u8, 1); - bar(@ptrCast(*anyopaque, &x)); + bar(@as(*anyopaque, @ptrCast(&x))); } // error |
