aboutsummaryrefslogtreecommitdiff
path: root/test/runtime_safety.zig
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2018-07-02 15:49:49 -0400
committerAndrew Kelley <superjoe30@gmail.com>2018-07-02 15:50:28 -0400
commit35463526cceb91243410bdab4d74e2d5b3c60f66 (patch)
tree98824c6dcd3f1fba0a45b84666815c8a9ee41207 /test/runtime_safety.zig
parent2759c7951da050d825cf765c4b660f5562fb01a4 (diff)
downloadzig-35463526cceb91243410bdab4d74e2d5b3c60f66.tar.gz
zig-35463526cceb91243410bdab4d74e2d5b3c60f66.zip
add runtime safety for `@intToEnum`; add docs for runtime safety
See #367
Diffstat (limited to 'test/runtime_safety.zig')
-rw-r--r--test/runtime_safety.zig18
1 files changed, 18 insertions, 0 deletions
diff --git a/test/runtime_safety.zig b/test/runtime_safety.zig
index a7e8d6dc0e..3d58dfe748 100644
--- a/test/runtime_safety.zig
+++ b/test/runtime_safety.zig
@@ -1,6 +1,24 @@
const tests = @import("tests.zig");
pub fn addCases(cases: *tests.CompareOutputContext) void {
+ cases.addRuntimeSafety("@intToEnum - no matching tag value",
+ \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
+ \\ @import("std").os.exit(126);
+ \\}
+ \\const Foo = enum {
+ \\ A,
+ \\ B,
+ \\ C,
+ \\};
+ \\pub fn main() void {
+ \\ baz(bar(3));
+ \\}
+ \\fn bar(a: u2) Foo {
+ \\ return @intToEnum(Foo, a);
+ \\}
+ \\fn baz(a: Foo) void {}
+ );
+
cases.addRuntimeSafety("@floatToInt cannot fit - negative to unsigned",
\\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
\\ @import("std").os.exit(126);