authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-02-08 03:02:41-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-02-08 03:02:41-05:00
log76239f2089bfb03b24dac0dcad21c9c430ad076d
tree6cb4afeeccdcac9f4ea1cf2f6d2a823aa107c8ad
parent0d5ff6f4622a492dddbb1fc2b19b3157237500b1

error sets - update langref. all tests passing


2 files changed, 49 insertions(+), 82 deletions(-)

doc/langref.html.in+43-60
...@@ -108,7 +108,7 @@...@@ -108,7 +108,7 @@
108 {#code_begin|exe|hello#}108 {#code_begin|exe|hello#}
109const std = @import("std");109const std = @import("std");
110110
111pub fn main() %void {111pub fn main() !void {
112 // If this program is run without stdout attached, exit with an error.112 // If this program is run without stdout attached, exit with an error.
113 var stdout_file = try std.io.getStdOut();113 var stdout_file = try std.io.getStdOut();
114 // If this program encounters pipe failure when printing to stdout, exit114 // If this program encounters pipe failure when printing to stdout, exit
...@@ -129,8 +129,8 @@ pub fn main() void {...@@ -129,8 +129,8 @@ pub fn main() void {
129}129}
130 {#code_end#}130 {#code_end#}
131 <p>131 <p>
132 Note that we also left off the <code class="zig">%</code> from the return type.132 Note that we also left off the <code class="zig">!</code> from the return type.
133 In Zig, if your main function cannot fail, you may use the <code class="zig">void</code> return type.133 In Zig, if your main function cannot fail, you must use the <code class="zig">void</code> return type.
134 </p>134 </p>
135 {#see_also|Values|@import|Errors|Root Source File#}135 {#see_also|Values|@import|Errors|Root Source File#}
136 {#header_close#}136 {#header_close#}
...@@ -151,10 +151,7 @@ const warn = std.debug.warn;...@@ -151,10 +151,7 @@ const warn = std.debug.warn;
151const os = std.os;151const os = std.os;
152const assert = std.debug.assert;152const assert = std.debug.assert;
153153
154// error declaration, makes `error.ArgNotFound` available154pub fn main() void {
155error ArgNotFound;
156
157pub fn main() %void {
158 // integers155 // integers
159 const one_plus_one: i32 = 1 + 1;156 const one_plus_one: i32 = 1 + 1;
160 warn("1 + 1 = {}\n", one_plus_one);157 warn("1 + 1 = {}\n", one_plus_one);
...@@ -183,7 +180,7 @@ pub fn main() %void {...@@ -183,7 +180,7 @@ pub fn main() %void {
183 @typeName(@typeOf(nullable_value)), nullable_value);180 @typeName(@typeOf(nullable_value)), nullable_value);
184181
185 // error union182 // error union
186 var number_or_error: %i32 = error.ArgNotFound;183 var number_or_error: error!i32 = error.ArgNotFound;
187184
188 warn("\nerror union 1\ntype: {}\nvalue: {}\n",185 warn("\nerror union 1\ntype: {}\nvalue: {}\n",
189 @typeName(@typeOf(number_or_error)), number_or_error);186 @typeName(@typeOf(number_or_error)), number_or_error);
...@@ -691,7 +688,7 @@ const warn = @import("std").debug.warn;...@@ -691,7 +688,7 @@ const warn = @import("std").debug.warn;
691extern fn foo_strict(x: f64) f64;688extern fn foo_strict(x: f64) f64;
692extern fn foo_optimized(x: f64) f64;689extern fn foo_optimized(x: f64) f64;
693690
694pub fn main() %void {691pub fn main() void {
695 const x = 0.001;692 const x = 0.001;
696 warn("optimized = {}\n", foo_optimized(x));693 warn("optimized = {}\n", foo_optimized(x));
697 warn("strict = {}\n", foo_strict(x));694 warn("strict = {}\n", foo_strict(x));
...@@ -1046,7 +1043,7 @@ a catch |err| b</code></pre></td>...@@ -1046,7 +1043,7 @@ a catch |err| b</code></pre></td>
1046 <code>err</code> is the <code>error</code> and is in scope of the expression <code>b</code>.1043 <code>err</code> is the <code>error</code> and is in scope of the expression <code>b</code>.
1047 </td>1044 </td>
1048 <td>1045 <td>
1049 <pre><code class="zig">const value: %u32 = null;1046 <pre><code class="zig">const value: error!u32 = error.Broken;
1050const unwrapped = value catch 1234;1047const unwrapped = value catch 1234;
1051unwrapped == 1234</code></pre>1048unwrapped == 1234</code></pre>
1052 </td>1049 </td>
...@@ -1279,7 +1276,8 @@ const ptr = &amp;x;...@@ -1279,7 +1276,8 @@ const ptr = &amp;x;
1279 {#header_close#}1276 {#header_close#}
1280 {#header_open|Precedence#}1277 {#header_open|Precedence#}
1281 <pre><code>x() x[] x.y1278 <pre><code>x() x[] x.y
1282!x -x -%x ~x *x &amp;x ?x %x ??x1279a!b
1280!x -x -%x ~x *x &amp;x ?x ??x
1283x{}1281x{}
1284! * / % ** *%1282! * / % ** *%
1285+ - ++ +% -%1283+ - ++ +% -%
...@@ -2278,8 +2276,8 @@ fn eventuallyNullSequence() ?u32 {...@@ -2278,8 +2276,8 @@ fn eventuallyNullSequence() ?u32 {
2278 break :blk numbers_left;2276 break :blk numbers_left;
2279 };2277 };
2280}2278}
2281error ReachedZero;2279
2282fn eventuallyErrorSequence() %u32 {2280fn eventuallyErrorSequence() error!u32 {
2283 return if (numbers_left == 0) error.ReachedZero else blk: {2281 return if (numbers_left == 0) error.ReachedZero else blk: {
2284 numbers_left -= 1;2282 numbers_left -= 1;
2285 break :blk numbers_left;2283 break :blk numbers_left;
...@@ -2408,7 +2406,7 @@ fn typeNameLength(comptime T: type) usize {...@@ -2408,7 +2406,7 @@ fn typeNameLength(comptime T: type) usize {
2408// If expressions have three uses, corresponding to the three types:2406// If expressions have three uses, corresponding to the three types:
2409// * bool2407// * bool
2410// * ?T2408// * ?T
2411// * %T2409// * error!T
24122410
2413const assert = @import("std").debug.assert;2411const assert = @import("std").debug.assert;
24142412
...@@ -2469,20 +2467,18 @@ test "if nullable" {...@@ -2469,20 +2467,18 @@ test "if nullable" {
2469 }2467 }
2470}2468}
24712469
2472error BadValue;
2473error LessBadValue;
2474test "if error union" {2470test "if error union" {
2475 // If expressions test for errors.2471 // If expressions test for errors.
2476 // Note the |err| capture on the else.2472 // Note the |err| capture on the else.
24772473
2478 const a: %u32 = 0;2474 const a: error!u32 = 0;
2479 if (a) |value| {2475 if (a) |value| {
2480 assert(value == 0);2476 assert(value == 0);
2481 } else |err| {2477 } else |err| {
2482 unreachable;2478 unreachable;
2483 }2479 }
24842480
2485 const b: %u32 = error.BadValue;2481 const b: error!u32 = error.BadValue;
2486 if (b) |value| {2482 if (b) |value| {
2487 unreachable;2483 unreachable;
2488 } else |err| {2484 } else |err| {
...@@ -2500,7 +2496,7 @@ test "if error union" {...@@ -2500,7 +2496,7 @@ test "if error union" {
2500 }2496 }
25012497
2502 // Access the value by reference using a pointer capture.2498 // Access the value by reference using a pointer capture.
2503 var c: %u32 = 3;2499 var c: error!u32 = 3;
2504 if (c) |*value| {2500 if (c) |*value| {
2505 *value = 9;2501 *value = 9;
2506 } else |err| {2502 } else |err| {
...@@ -2568,8 +2564,7 @@ test "defer unwinding" {...@@ -2568,8 +2564,7 @@ test "defer unwinding" {
2568//2564//
2569// This is especially useful in allowing a function to clean up properly2565// This is especially useful in allowing a function to clean up properly
2570// on error, and replaces goto error handling tactics as seen in c.2566// on error, and replaces goto error handling tactics as seen in c.
2571error DeferError;2567fn deferErrorExample(is_error: bool) !void {
2572fn deferErrorExample(is_error: bool) %void {
2573 warn("\nstart of function\n");2568 warn("\nstart of function\n");
25742569
2575 // This will always be executed on exit2570 // This will always be executed on exit
...@@ -2678,7 +2673,7 @@ test "foo" {...@@ -2678,7 +2673,7 @@ test "foo" {
2678 assert(value == 1234);2673 assert(value == 1234);
2679}2674}
26802675
2681fn bar() %u32 {2676fn bar() error!u32 {
2682 return 1234;2677 return 1234;
2683}2678}
26842679
...@@ -2791,13 +2786,8 @@ test "implicitly cast to const pointer" {...@@ -2791,13 +2786,8 @@ test "implicitly cast to const pointer" {
2791 One of the distinguishing features of Zig is its exception handling strategy.2786 One of the distinguishing features of Zig is its exception handling strategy.
2792 </p>2787 </p>
2793 <p>2788 <p>
2794 Among the top level declarations available is the error value declaration:2789 TODO rewrite the errors section to take into account error sets
2795 </p>2790 </p>
2796 {#code_begin|syntax#}
2797error FileNotFound;
2798error OutOfMemory;
2799error UnexpectedToken;
2800 {#code_end#}
2801 <p>2791 <p>
2802 These error values are assigned an unsigned integer value greater than 0 at2792 These error values are assigned an unsigned integer value greater than 0 at
2803 compile time. You are allowed to declare the same error value more than once,2793 compile time. You are allowed to declare the same error value more than once,
...@@ -2809,26 +2799,23 @@ error UnexpectedToken;...@@ -2809,26 +2799,23 @@ error UnexpectedToken;
2809 </p>2799 </p>
2810 <p>2800 <p>
2811 Each error value across the entire compilation unit gets a unique integer,2801 Each error value across the entire compilation unit gets a unique integer,
2812 and this determines the size of the pure error type.2802 and this determines the size of the error set type.
2813 </p>2803 </p>
2814 <p>2804 <p>
2815 The pure error type is one of the error values, and in the same way that pointers2805 The error set type is one of the error values, and in the same way that pointers
2816 cannot be null, a pure error is always an error.2806 cannot be null, a error set instance is always an error.
2817 </p>2807 </p>
2818 {#code_begin|syntax#}const pure_error = error.FileNotFound;{#code_end#}2808 {#code_begin|syntax#}const pure_error = error.FileNotFound;{#code_end#}
2819 <p>2809 <p>
2820 Most of the time you will not find yourself using a pure error type. Instead,2810 Most of the time you will not find yourself using an error set type. Instead,
2821 likely you will be using the error union type. This is when you take a normal type,2811 likely you will be using the error union type. This is when you take an error set
2822 and prefix it with the <code>%</code> operator.2812 and a normal type, and create an error union with the <code>!</code> binary operator.
2823 </p>2813 </p>
2824 <p>2814 <p>
2825 Here is a function to parse a string into a 64-bit integer:2815 Here is a function to parse a string into a 64-bit integer:
2826 </p>2816 </p>
2827 {#code_begin|test#}2817 {#code_begin|test#}
2828error InvalidChar;2818pub fn parseU64(buf: []const u8, radix: u8) !u64 {
2829error Overflow;
2830
2831pub fn parseU64(buf: []const u8, radix: u8) %u64 {
2832 var x: u64 = 0;2819 var x: u64 = 0;
28332820
2834 for (buf) |c| {2821 for (buf) |c| {
...@@ -2867,13 +2854,14 @@ test "parse u64" {...@@ -2867,13 +2854,14 @@ test "parse u64" {
2867}2854}
2868 {#code_end#}2855 {#code_end#}
2869 <p>2856 <p>
2870 Notice the return type is <code>%u64</code>. This means that the function2857 Notice the return type is <code>!u64</code>. This means that the function
2871 either returns an unsigned 64 bit integer, or an error.2858 either returns an unsigned 64 bit integer, or an error. We left off the error set
2859 to the left of the <code>!</code>, so the error set is inferred.
2872 </p>2860 </p>
2873 <p>2861 <p>
2874 Within the function definition, you can see some return statements that return2862 Within the function definition, you can see some return statements that return
2875 a pure error, and at the bottom a return statement that returns a <code>u64</code>.2863 an error, and at the bottom a return statement that returns a <code>u64</code>.
2876 Both types implicitly cast to <code>%u64</code>.2864 Both types implicitly cast to <code>error!u64</code>.
2877 </p>2865 </p>
2878 <p>2866 <p>
2879 What it looks like to use this function varies depending on what you're2867 What it looks like to use this function varies depending on what you're
...@@ -2900,7 +2888,7 @@ fn doAThing(str: []u8) void {...@@ -2900,7 +2888,7 @@ fn doAThing(str: []u8) void {
2900 <p>Let's say you wanted to return the error if you got one, otherwise continue with the2888 <p>Let's say you wanted to return the error if you got one, otherwise continue with the
2901 function logic:</p>2889 function logic:</p>
2902 {#code_begin|syntax#}2890 {#code_begin|syntax#}
2903fn doAThing(str: []u8) %void {2891fn doAThing(str: []u8) !void {
2904 const number = parseU64(str, 10) catch |err| return err;2892 const number = parseU64(str, 10) catch |err| return err;
2905 // ...2893 // ...
2906}2894}
...@@ -2909,7 +2897,7 @@ fn doAThing(str: []u8) %void {...@@ -2909,7 +2897,7 @@ fn doAThing(str: []u8) %void {
2909 There is a shortcut for this. The <code>try</code> expression:2897 There is a shortcut for this. The <code>try</code> expression:
2910 </p>2898 </p>
2911 {#code_begin|syntax#}2899 {#code_begin|syntax#}
2912fn doAThing(str: []u8) %void {2900fn doAThing(str: []u8) !void {
2913 const number = try parseU64(str, 10);2901 const number = try parseU64(str, 10);
2914 // ...2902 // ...
2915}2903}
...@@ -2959,7 +2947,7 @@ fn doAThing(str: []u8) void {...@@ -2959,7 +2947,7 @@ fn doAThing(str: []u8) void {
2959 Example:2947 Example:
2960 </p>2948 </p>
2961 {#code_begin|syntax#}2949 {#code_begin|syntax#}
2962fn createFoo(param: i32) %Foo {2950fn createFoo(param: i32) !Foo {
2963 const foo = try tryToAllocateFoo();2951 const foo = try tryToAllocateFoo();
2964 // now we have allocated foo. we need to free it if the function fails.2952 // now we have allocated foo. we need to free it if the function fails.
2965 // but we want to return it if the function succeeds.2953 // but we want to return it if the function succeeds.
...@@ -3567,7 +3555,7 @@ pub fn main() void {...@@ -3567,7 +3555,7 @@ pub fn main() void {
35673555
3568 {#code_begin|syntax#}3556 {#code_begin|syntax#}
3569/// Calls print and then flushes the buffer.3557/// Calls print and then flushes the buffer.
3570pub fn printf(self: &OutStream, comptime format: []const u8, args: ...) %void {3558pub fn printf(self: &OutStream, comptime format: []const u8, args: ...) error!void {
3571 const State = enum {3559 const State = enum {
3572 Start,3560 Start,
3573 OpenBrace,3561 OpenBrace,
...@@ -3639,7 +3627,7 @@ pub fn printf(self: &OutStream, comptime format: []const u8, args: ...) %void {...@@ -3639,7 +3627,7 @@ pub fn printf(self: &OutStream, comptime format: []const u8, args: ...) %void {
3639 and emits a function that actually looks like this:3627 and emits a function that actually looks like this:
3640 </p>3628 </p>
3641 {#code_begin|syntax#}3629 {#code_begin|syntax#}
3642pub fn printf(self: &OutStream, arg0: i32, arg1: []const u8) %void {3630pub fn printf(self: &OutStream, arg0: i32, arg1: []const u8) !void {
3643 try self.write("here is a string: '");3631 try self.write("here is a string: '");
3644 try self.printValue(arg0);3632 try self.printValue(arg0);
3645 try self.write("' here is a number: ");3633 try self.write("' here is a number: ");
...@@ -3653,7 +3641,7 @@ pub fn printf(self: &OutStream, arg0: i32, arg1: []const u8) %void {...@@ -3653,7 +3641,7 @@ pub fn printf(self: &OutStream, arg0: i32, arg1: []const u8) %void {
3653 on the type:3641 on the type:
3654 </p>3642 </p>
3655 {#code_begin|syntax#}3643 {#code_begin|syntax#}
3656pub fn printValue(self: &OutStream, value: var) %void {3644pub fn printValue(self: &OutStream, value: var) !void {
3657 const T = @typeOf(value);3645 const T = @typeOf(value);
3658 if (@isInteger(T)) {3646 if (@isInteger(T)) {
3659 return self.printInt(T, value);3647 return self.printInt(T, value);
...@@ -4582,7 +4570,7 @@ pub const TypeId = enum {...@@ -4582,7 +4570,7 @@ pub const TypeId = enum {
4582 {#code_begin|syntax#}4570 {#code_begin|syntax#}
4583const Builder = @import("std").build.Builder;4571const Builder = @import("std").build.Builder;
45844572
4585pub fn build(b: &Builder) %void {4573pub fn build(b: &Builder) void {
4586 const exe = b.addExecutable("example", "example.zig");4574 const exe = b.addExecutable("example", "example.zig");
4587 exe.setBuildMode(b.standardReleaseOptions());4575 exe.setBuildMode(b.standardReleaseOptions());
4588 b.default_step.dependOn(&exe.step);4576 b.default_step.dependOn(&exe.step);
...@@ -4724,7 +4712,7 @@ comptime {...@@ -4724,7 +4712,7 @@ comptime {
4724 {#code_begin|exe_err#}4712 {#code_begin|exe_err#}
4725const math = @import("std").math;4713const math = @import("std").math;
4726const warn = @import("std").debug.warn;4714const warn = @import("std").debug.warn;
4727pub fn main() %void {4715pub fn main() !void {
4728 var byte: u8 = 255;4716 var byte: u8 = 255;
47294717
4730 byte = if (math.add(u8, byte, 1)) |result| result else |err| {4718 byte = if (math.add(u8, byte, 1)) |result| result else |err| {
...@@ -4752,7 +4740,7 @@ pub fn main() %void {...@@ -4752,7 +4740,7 @@ pub fn main() %void {
4752 </p>4740 </p>
4753 {#code_begin|exe#}4741 {#code_begin|exe#}
4754const warn = @import("std").debug.warn;4742const warn = @import("std").debug.warn;
4755pub fn main() %void {4743pub fn main() void {
4756 var byte: u8 = 255;4744 var byte: u8 = 255;
47574745
4758 var result: u8 = undefined;4746 var result: u8 = undefined;
...@@ -4861,14 +4849,12 @@ pub fn main() void {...@@ -4861,14 +4849,12 @@ pub fn main() void {
4861 {#header_close#}4849 {#header_close#}
4862 {#header_open|Attempt to Unwrap Error#}4850 {#header_open|Attempt to Unwrap Error#}
4863 <p>At compile-time:</p>4851 <p>At compile-time:</p>
4864 {#code_begin|test_err|unable to unwrap error 'UnableToReturnNumber'#}4852 {#code_begin|test_err|caught unexpected error 'UnableToReturnNumber'#}
4865comptime {4853comptime {
4866 const number = getNumberOrFail() catch unreachable;4854 const number = getNumberOrFail() catch unreachable;
4867}4855}
48684856
4869error UnableToReturnNumber;4857fn getNumberOrFail() !i32 {
4870
4871fn getNumberOrFail() %i32 {
4872 return error.UnableToReturnNumber;4858 return error.UnableToReturnNumber;
4873}4859}
4874 {#code_end#}4860 {#code_end#}
...@@ -4888,9 +4874,7 @@ pub fn main() void {...@@ -4888,9 +4874,7 @@ pub fn main() void {
4888 }4874 }
4889}4875}
48904876
4891error UnableToReturnNumber;4877fn getNumberOrFail() !i32 {
4892
4893fn getNumberOrFail() %i32 {
4894 return error.UnableToReturnNumber;4878 return error.UnableToReturnNumber;
4895}4879}
4896 {#code_end#}4880 {#code_end#}
...@@ -4898,7 +4882,6 @@ fn getNumberOrFail() %i32 {...@@ -4898,7 +4882,6 @@ fn getNumberOrFail() %i32 {
4898 {#header_open|Invalid Error Code#}4882 {#header_open|Invalid Error Code#}
4899 <p>At compile-time:</p>4883 <p>At compile-time:</p>
4900 {#code_begin|test_err|integer value 11 represents no error#}4884 {#code_begin|test_err|integer value 11 represents no error#}
4901error AnError;
4902comptime {4885comptime {
4903 const err = error.AnError;4886 const err = error.AnError;
4904 const number = u32(err) + 10;4887 const number = u32(err) + 10;
...@@ -5298,7 +5281,7 @@ int main(int argc, char **argv) {...@@ -5298,7 +5281,7 @@ int main(int argc, char **argv) {
5298 {#code_begin|syntax#}5281 {#code_begin|syntax#}
5299const Builder = @import("std").build.Builder;5282const Builder = @import("std").build.Builder;
53005283
5301pub fn build(b: &Builder) %void {5284pub fn build(b: &Builder) void {
5302 const obj = b.addObject("base64", "base64.zig");5285 const obj = b.addObject("base64", "base64.zig");
53035286
5304 const exe = b.addCExecutable("test");5287 const exe = b.addCExecutable("test");
test/runtime_safety.zig+6-22
...@@ -5,7 +5,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {...@@ -5,7 +5,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {
5 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn {5 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn {
6 \\ @import("std").os.exit(126);6 \\ @import("std").os.exit(126);
7 \\}7 \\}
8 \\pub fn main() !void {8 \\pub fn main() void {
9 \\ @panic("oh no");9 \\ @panic("oh no");
10 \\}10 \\}
11 );11 );
...@@ -14,7 +14,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {...@@ -14,7 +14,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {
14 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn {14 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn {
15 \\ @import("std").os.exit(126);15 \\ @import("std").os.exit(126);
16 \\}16 \\}
17 \\pub fn main() !void {17 \\pub fn main() void {
18 \\ const a = []i32{1, 2, 3, 4};18 \\ const a = []i32{1, 2, 3, 4};
19 \\ baz(bar(a));19 \\ baz(bar(a));
20 \\}20 \\}
...@@ -28,7 +28,6 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {...@@ -28,7 +28,6 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {
28 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn {28 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn {
29 \\ @import("std").os.exit(126);29 \\ @import("std").os.exit(126);
30 \\}30 \\}
31 \\error Whatever;
32 \\pub fn main() !void {31 \\pub fn main() !void {
33 \\ const x = add(65530, 10);32 \\ const x = add(65530, 10);
34 \\ if (x == 0) return error.Whatever;33 \\ if (x == 0) return error.Whatever;
...@@ -42,7 +41,6 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {...@@ -42,7 +41,6 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {
42 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn {41 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn {
43 \\ @import("std").os.exit(126);42 \\ @import("std").os.exit(126);
44 \\}43 \\}
45 \\error Whatever;
46 \\pub fn main() !void {44 \\pub fn main() !void {
47 \\ const x = sub(10, 20);45 \\ const x = sub(10, 20);
48 \\ if (x == 0) return error.Whatever;46 \\ if (x == 0) return error.Whatever;
...@@ -56,7 +54,6 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {...@@ -56,7 +54,6 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {
56 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn {54 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn {
57 \\ @import("std").os.exit(126);55 \\ @import("std").os.exit(126);
58 \\}56 \\}
59 \\error Whatever;
60 \\pub fn main() !void {57 \\pub fn main() !void {
61 \\ const x = mul(300, 6000);58 \\ const x = mul(300, 6000);
62 \\ if (x == 0) return error.Whatever;59 \\ if (x == 0) return error.Whatever;
...@@ -70,7 +67,6 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {...@@ -70,7 +67,6 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {
70 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn {67 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn {
71 \\ @import("std").os.exit(126);68 \\ @import("std").os.exit(126);
72 \\}69 \\}
73 \\error Whatever;
74 \\pub fn main() !void {70 \\pub fn main() !void {
75 \\ const x = neg(-32768);71 \\ const x = neg(-32768);
76 \\ if (x == 32767) return error.Whatever;72 \\ if (x == 32767) return error.Whatever;
...@@ -84,7 +80,6 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {...@@ -84,7 +80,6 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {
84 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn {80 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn {
85 \\ @import("std").os.exit(126);81 \\ @import("std").os.exit(126);
86 \\}82 \\}
87 \\error Whatever;
88 \\pub fn main() !void {83 \\pub fn main() !void {
89 \\ const x = div(-32768, -1);84 \\ const x = div(-32768, -1);
90 \\ if (x == 32767) return error.Whatever;85 \\ if (x == 32767) return error.Whatever;
...@@ -98,7 +93,6 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {...@@ -98,7 +93,6 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {
98 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn {93 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn {
99 \\ @import("std").os.exit(126);94 \\ @import("std").os.exit(126);
100 \\}95 \\}
101 \\error Whatever;
102 \\pub fn main() !void {96 \\pub fn main() !void {
103 \\ const x = shl(-16385, 1);97 \\ const x = shl(-16385, 1);
104 \\ if (x == 0) return error.Whatever;98 \\ if (x == 0) return error.Whatever;
...@@ -112,7 +106,6 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {...@@ -112,7 +106,6 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {
112 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn {106 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn {
113 \\ @import("std").os.exit(126);107 \\ @import("std").os.exit(126);
114 \\}108 \\}
115 \\error Whatever;
116 \\pub fn main() !void {109 \\pub fn main() !void {
117 \\ const x = shl(0b0010111111111111, 3);110 \\ const x = shl(0b0010111111111111, 3);
118 \\ if (x == 0) return error.Whatever;111 \\ if (x == 0) return error.Whatever;
...@@ -126,7 +119,6 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {...@@ -126,7 +119,6 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {
126 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn {119 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn {
127 \\ @import("std").os.exit(126);120 \\ @import("std").os.exit(126);
128 \\}121 \\}
129 \\error Whatever;
130 \\pub fn main() !void {122 \\pub fn main() !void {
131 \\ const x = shr(-16385, 1);123 \\ const x = shr(-16385, 1);
132 \\ if (x == 0) return error.Whatever;124 \\ if (x == 0) return error.Whatever;
...@@ -140,7 +132,6 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {...@@ -140,7 +132,6 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {
140 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn {132 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn {
141 \\ @import("std").os.exit(126);133 \\ @import("std").os.exit(126);
142 \\}134 \\}
143 \\error Whatever;
144 \\pub fn main() !void {135 \\pub fn main() !void {
145 \\ const x = shr(0b0010111111111111, 3);136 \\ const x = shr(0b0010111111111111, 3);
146 \\ if (x == 0) return error.Whatever;137 \\ if (x == 0) return error.Whatever;
...@@ -154,8 +145,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {...@@ -154,8 +145,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {
154 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn {145 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn {
155 \\ @import("std").os.exit(126);146 \\ @import("std").os.exit(126);
156 \\}147 \\}
157 \\error Whatever;148 \\pub fn main() void {
158 \\pub fn main() !void {
159 \\ const x = div0(999, 0);149 \\ const x = div0(999, 0);
160 \\}150 \\}
161 \\fn div0(a: i32, b: i32) i32 {151 \\fn div0(a: i32, b: i32) i32 {
...@@ -167,7 +157,6 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {...@@ -167,7 +157,6 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {
167 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn {157 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn {
168 \\ @import("std").os.exit(126);158 \\ @import("std").os.exit(126);
169 \\}159 \\}
170 \\error Whatever;
171 \\pub fn main() !void {160 \\pub fn main() !void {
172 \\ const x = divExact(10, 3);161 \\ const x = divExact(10, 3);
173 \\ if (x == 0) return error.Whatever;162 \\ if (x == 0) return error.Whatever;
...@@ -181,7 +170,6 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {...@@ -181,7 +170,6 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {
181 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn {170 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn {
182 \\ @import("std").os.exit(126);171 \\ @import("std").os.exit(126);
183 \\}172 \\}
184 \\error Whatever;
185 \\pub fn main() !void {173 \\pub fn main() !void {
186 \\ const x = widenSlice([]u8{1, 2, 3, 4, 5});174 \\ const x = widenSlice([]u8{1, 2, 3, 4, 5});
187 \\ if (x.len == 0) return error.Whatever;175 \\ if (x.len == 0) return error.Whatever;
...@@ -195,7 +183,6 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {...@@ -195,7 +183,6 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {
195 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn {183 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn {
196 \\ @import("std").os.exit(126);184 \\ @import("std").os.exit(126);
197 \\}185 \\}
198 \\error Whatever;
199 \\pub fn main() !void {186 \\pub fn main() !void {
200 \\ const x = shorten_cast(200);187 \\ const x = shorten_cast(200);
201 \\ if (x == 0) return error.Whatever;188 \\ if (x == 0) return error.Whatever;
...@@ -209,7 +196,6 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {...@@ -209,7 +196,6 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {
209 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn {196 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn {
210 \\ @import("std").os.exit(126);197 \\ @import("std").os.exit(126);
211 \\}198 \\}
212 \\error Whatever;
213 \\pub fn main() !void {199 \\pub fn main() !void {
214 \\ const x = unsigned_cast(-10);200 \\ const x = unsigned_cast(-10);
215 \\ if (x == 0) return error.Whatever;201 \\ if (x == 0) return error.Whatever;
...@@ -226,8 +212,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {...@@ -226,8 +212,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {
226 \\ }212 \\ }
227 \\ @import("std").os.exit(0); // test failed213 \\ @import("std").os.exit(0); // test failed
228 \\}214 \\}
229 \\error Whatever;215 \\pub fn main() void {
230 \\pub fn main() !void {
231 \\ bar() catch unreachable;216 \\ bar() catch unreachable;
232 \\}217 \\}
233 \\fn bar() !void {218 \\fn bar() !void {
...@@ -239,7 +224,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {...@@ -239,7 +224,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {
239 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn {224 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn {
240 \\ @import("std").os.exit(126);225 \\ @import("std").os.exit(126);
241 \\}226 \\}
242 \\pub fn main() !void {227 \\pub fn main() void {
243 \\ _ = bar(9999);228 \\ _ = bar(9999);
244 \\}229 \\}
245 \\fn bar(x: u32) error {230 \\fn bar(x: u32) error {
...@@ -251,7 +236,6 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {...@@ -251,7 +236,6 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {
251 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn {236 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn {
252 \\ @import("std").os.exit(126);237 \\ @import("std").os.exit(126);
253 \\}238 \\}
254 \\error Wrong;
255 \\pub fn main() !void {239 \\pub fn main() !void {
256 \\ var array align(4) = []u32{0x11111111, 0x11111111};240 \\ var array align(4) = []u32{0x11111111, 0x11111111};
257 \\ const bytes = ([]u8)(array[0..]);241 \\ const bytes = ([]u8)(array[0..]);
...@@ -274,7 +258,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {...@@ -274,7 +258,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {
274 \\ int: u32,258 \\ int: u32,
275 \\};259 \\};
276 \\260 \\
277 \\pub fn main() !void {261 \\pub fn main() void {
278 \\ var f = Foo { .int = 42 };262 \\ var f = Foo { .int = 42 };
279 \\ bar(&f);263 \\ bar(&f);
280 \\}264 \\}