diff options
| author | Veikka Tuominen <git@vexu.eu> | 2022-07-10 16:51:10 +0300 |
|---|---|---|
| committer | Veikka Tuominen <git@vexu.eu> | 2022-07-10 23:47:56 +0300 |
| commit | 34fe2b4f4be29efa8f4ba4b9f32b22373fdddc22 (patch) | |
| tree | 8227137b718913e1997324cac2642e66375836bc /test | |
| parent | b9f01bc39452042be1609b63f3066cfcac82f273 (diff) | |
| download | zig-34fe2b4f4be29efa8f4ba4b9f32b22373fdddc22.tar.gz zig-34fe2b4f4be29efa8f4ba4b9f32b22373fdddc22.zip | |
Sema: prefer original error message in `coerce`
Diffstat (limited to 'test')
5 files changed, 37 insertions, 21 deletions
diff --git a/test/cases/compile_errors/any_typed_null_to_any_typed_optional.zig b/test/cases/compile_errors/any_typed_null_to_any_typed_optional.zig index ad6427d224..6b3ffaca2f 100644 --- a/test/cases/compile_errors/any_typed_null_to_any_typed_optional.zig +++ b/test/cases/compile_errors/any_typed_null_to_any_typed_optional.zig @@ -1,11 +1,11 @@ -pub fn main() void { +pub export fn entry() void { var a: ?*anyopaque = undefined; a = @as(?usize, null); } // error -// output_mode=Exe -// backend=stage2,llvm -// target=x86_64-linux,x86_64-macos +// backend=stage2 +// target=native // -// :3:21: error: expected type '*anyopaque', found '?usize' +// :3:21: error: expected type '?*anyopaque', found '?usize' +// :3:21: note: optional type child 'usize' cannot cast into optional type child '*anyopaque' diff --git a/test/cases/compile_errors/cast_between_optional_T_where_T_is_not_a_pointer.zig b/test/cases/compile_errors/cast_between_optional_T_where_T_is_not_a_pointer.zig new file mode 100644 index 0000000000..a09059eb3e --- /dev/null +++ b/test/cases/compile_errors/cast_between_optional_T_where_T_is_not_a_pointer.zig @@ -0,0 +1,16 @@ +pub const fnty1 = ?*const fn (i8) void; +pub const fnty2 = ?*const fn (u64) void; +export fn entry() void { + var a: fnty1 = undefined; + var b: fnty2 = undefined; + a = b; +} + +// error +// backend=stage2 +// target=native +// +// :6:9: error: expected type '?*const fn(i8) void', found '?*const fn(u64) void' +// :6:9: note: pointer type child 'fn(u64) void' cannot cast into pointer type child 'fn(i8) void' +// :6:9: note: parameter 0 'u64' cannot cast into 'i8' +// :6:9: note: unsigned 64-bit int cannot represent all possible signed 8-bit values diff --git a/test/cases/compile_errors/implicit_cast_to_c_ptr_from_int.zig b/test/cases/compile_errors/implicit_cast_to_c_ptr_from_int.zig new file mode 100644 index 0000000000..bcf15569ff --- /dev/null +++ b/test/cases/compile_errors/implicit_cast_to_c_ptr_from_int.zig @@ -0,0 +1,15 @@ +const std = @import("std"); +export fn entry1() void { + _ = @as([*c]u8, @as(u65, std.math.maxInt(u65))); +} +export fn entry2() void { + _ = @as([*c]u8, std.math.maxInt(u65)); +} + +// error +// backend=stage2 +// target=native +// +// :3:21: error: expected type '[*c]u8', found 'u65' +// :3:21: note: unsigned 64-bit int cannot represent all possible unsigned 65-bit values +// :6:36: error: expected type '[*c]u8', found 'comptime_int' diff --git a/test/cases/compile_errors/stage1/test/cast_between_optional_T_where_T_is_not_a_pointer.zig b/test/cases/compile_errors/stage1/test/cast_between_optional_T_where_T_is_not_a_pointer.zig deleted file mode 100644 index b8392ff5db..0000000000 --- a/test/cases/compile_errors/stage1/test/cast_between_optional_T_where_T_is_not_a_pointer.zig +++ /dev/null @@ -1,15 +0,0 @@ -pub const fnty1 = ?fn (i8) void; -pub const fnty2 = ?fn (u64) void; -export fn entry() void { - var a: fnty1 = undefined; - var b: fnty2 = undefined; - a = b; -} - -// error -// backend=stage1 -// target=native -// is_test=1 -// -// tmp.zig:6:9: error: expected type '?fn(i8) void', found '?fn(u64) void' -// tmp.zig:6:9: note: optional type child 'fn(u64) void' cannot cast into optional type child 'fn(i8) void' diff --git a/test/cases/compile_errors/type_mismatch_in_C_prototype_with_varargs.zig b/test/cases/compile_errors/type_mismatch_in_C_prototype_with_varargs.zig index 1e7acb55b8..66256fc9e9 100644 --- a/test/cases/compile_errors/type_mismatch_in_C_prototype_with_varargs.zig +++ b/test/cases/compile_errors/type_mismatch_in_C_prototype_with_varargs.zig @@ -10,6 +10,6 @@ export fn main() void { // backend=stage2 // target=native // -// :5:22: error: expected type 'fn([*c]u8, ...) callconv(.C) void', found 'fn([*:0]u8, ...) callconv(.C) void' +// :5:22: error: expected type '?fn([*c]u8, ...) callconv(.C) void', found 'fn([*:0]u8, ...) callconv(.C) void' // :5:22: note: parameter 0 '[*:0]u8' cannot cast into '[*c]u8' // :5:22: note: '[*c]u8' could have null values which are illegal in type '[*:0]u8' |
