mirror of
https://codeberg.org/ziglang/zig.git
synced 2026-04-27 19:09:47 +03:00
stage1: make @truncate to an integer type of different sign an error at comptime too
This commit is contained in:
committed by
Veikka Tuominen
parent
ff0a15bb7a
commit
9ac6d28614
+16
-3
@@ -6031,14 +6031,27 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
|
||||
});
|
||||
|
||||
cases.add("truncate sign mismatch",
|
||||
\\fn f() i8 {
|
||||
\\export fn entry1() i8 {
|
||||
\\ var x: u32 = 10;
|
||||
\\ return @truncate(i8, x);
|
||||
\\}
|
||||
\\
|
||||
\\export fn entry() usize { return @sizeOf(@TypeOf(f)); }
|
||||
\\export fn entry2() u8 {
|
||||
\\ var x: i32 = -10;
|
||||
\\ return @truncate(u8, x);
|
||||
\\}
|
||||
\\export fn entry3() i8 {
|
||||
\\ comptime var x: u32 = 10;
|
||||
\\ return @truncate(i8, x);
|
||||
\\}
|
||||
\\export fn entry4() u8 {
|
||||
\\ comptime var x: i32 = -10;
|
||||
\\ return @truncate(u8, x);
|
||||
\\}
|
||||
, &[_][]const u8{
|
||||
"tmp.zig:3:26: error: expected signed integer type, found 'u32'",
|
||||
"tmp.zig:7:26: error: expected unsigned integer type, found 'i32'",
|
||||
"tmp.zig:11:26: error: expected signed integer type, found 'u32'",
|
||||
"tmp.zig:15:26: error: expected unsigned integer type, found 'i32'",
|
||||
});
|
||||
|
||||
cases.add("try in function with non error return type",
|
||||
|
||||
Reference in New Issue
Block a user