File tree Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -1066,6 +1066,7 @@ pub fn orderAgainstZeroInner(
1066
1066
.float = > | float | switch (float .storage ) {
1067
1067
inline else = > | x | std .math .order (x , 0 ),
1068
1068
},
1069
+ .err = > .gt , // error values cannot be 0
1069
1070
else = > unreachable ,
1070
1071
},
1071
1072
};
Original file line number Diff line number Diff line change @@ -74,6 +74,31 @@ test "switch loop on enum" {
74
74
try comptime S .doTheTest ();
75
75
}
76
76
77
+ test "switch loop with error set" {
78
+ if (builtin .zig_backend == .stage2_wasm ) return error .SkipZigTest ; // TODO
79
+ if (builtin .zig_backend == .stage2_aarch64 ) return error .SkipZigTest ; // TODO
80
+ if (builtin .zig_backend == .stage2_arm ) return error .SkipZigTest ; // TODO
81
+ if (builtin .zig_backend == .stage2_sparc64 ) return error .SkipZigTest ; // TODO
82
+ if (builtin .zig_backend == .stage2_spirv64 ) return error .SkipZigTest ; // TODO
83
+
84
+ const S = struct {
85
+ const E = error { Foo , Bar , Baz };
86
+
87
+ fn doTheTest () ! void {
88
+ var start : E = undefined ;
89
+ start = error .Foo ;
90
+ const result : u32 = s : switch (start ) {
91
+ error .Foo = > continue :s error .Bar ,
92
+ error .Bar = > continue :s error .Baz ,
93
+ error .Baz = > 123 ,
94
+ };
95
+ try expect (result == 123 );
96
+ }
97
+ };
98
+ try S .doTheTest ();
99
+ try comptime S .doTheTest ();
100
+ }
101
+
77
102
test "switch loop on tagged union" {
78
103
if (builtin .zig_backend == .stage2_wasm ) return error .SkipZigTest ; // TODO
79
104
if (builtin .zig_backend == .stage2_aarch64 ) return error .SkipZigTest ; // TODO
You can’t perform that action at this time.
0 commit comments