diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2018-07-02 15:49:49 -0400 |
|---|---|---|
| committer | Andrew Kelley <superjoe30@gmail.com> | 2018-07-02 15:50:28 -0400 |
| commit | 35463526cceb91243410bdab4d74e2d5b3c60f66 (patch) | |
| tree | 98824c6dcd3f1fba0a45b84666815c8a9ee41207 /test/runtime_safety.zig | |
| parent | 2759c7951da050d825cf765c4b660f5562fb01a4 (diff) | |
| download | zig-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.zig | 18 |
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); |
