aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2018-09-17 20:32:51 -0400
committerAndrew Kelley <superjoe30@gmail.com>2018-09-17 20:33:42 -0400
commitbfcfaaf5bd5d2586d815ca5c10009975acf3e514 (patch)
treec2a3580527c2fae812a9fc2c2af37679d7e4a33f /test
parent15e59eb142af9d4385b9ce5a277df27804e1794e (diff)
downloadzig-bfcfaaf5bd5d2586d815ca5c10009975acf3e514.tar.gz
zig-bfcfaaf5bd5d2586d815ca5c10009975acf3e514.zip
fix codegen for @intCast to u0
Diffstat (limited to 'test')
-rw-r--r--test/cases/eval.zig7
-rw-r--r--test/runtime_safety.zig13
2 files changed, 20 insertions, 0 deletions
diff --git a/test/cases/eval.zig b/test/cases/eval.zig
index 104fa8f58c..5f456364a5 100644
--- a/test/cases/eval.zig
+++ b/test/cases/eval.zig
@@ -692,4 +692,11 @@ test "zero extend from u0 to u1" {
test "bit shift a u1" {
var x: u1 = 1;
var y = x << 0;
+ assert(y == 1);
+}
+
+test "@intCast to a u0" {
+ var x: u8 = 0;
+ var y: u0 = @intCast(u0, x);
+ assert(y == 0);
}
diff --git a/test/runtime_safety.zig b/test/runtime_safety.zig
index 3d58dfe748..ece6c2283a 100644
--- a/test/runtime_safety.zig
+++ b/test/runtime_safety.zig
@@ -249,6 +249,19 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
\\}
);
+ cases.addRuntimeSafety("value does not fit in shortening cast - u0",
+ \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
+ \\ @import("std").os.exit(126);
+ \\}
+ \\pub fn main() !void {
+ \\ const x = shorten_cast(1);
+ \\ if (x == 0) return error.Whatever;
+ \\}
+ \\fn shorten_cast(x: u8) u0 {
+ \\ return @intCast(u0, x);
+ \\}
+ );
+
cases.addRuntimeSafety("signed integer not fitting in cast to unsigned integer",
\\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
\\ @import("std").os.exit(126);