2017-01-05 16:57:48 +08:00
|
|
|
const assert = @import("std").debug.assert;
|
|
|
|
|
2016-09-23 14:00:23 +08:00
|
|
|
var read_count: u64 = 0;
|
|
|
|
|
2018-02-03 03:26:14 +08:00
|
|
|
fn readOnce() error!u64 {
|
2016-09-23 14:00:23 +08:00
|
|
|
read_count += 1;
|
|
|
|
return read_count;
|
|
|
|
}
|
|
|
|
|
2017-12-04 09:43:56 +08:00
|
|
|
const FormValue = union(enum) {
|
2016-09-23 14:00:23 +08:00
|
|
|
Address: u64,
|
|
|
|
Other: bool,
|
2016-12-26 07:31:57 +08:00
|
|
|
};
|
2016-09-23 14:00:23 +08:00
|
|
|
|
2018-02-03 03:26:14 +08:00
|
|
|
fn doThing(form_id: u64) error!FormValue {
|
2016-09-23 14:00:23 +08:00
|
|
|
return switch (form_id) {
|
2018-05-29 08:23:55 +08:00
|
|
|
17 => FormValue{ .Address = try readOnce() },
|
2016-09-23 14:00:23 +08:00
|
|
|
else => error.InvalidDebugInfo,
|
2017-12-22 13:50:30 +08:00
|
|
|
};
|
2016-09-23 14:00:23 +08:00
|
|
|
}
|
|
|
|
|
2017-05-24 09:38:31 +08:00
|
|
|
test "switch prong returns error enum" {
|
2018-01-09 13:07:01 +08:00
|
|
|
switch (doThing(17) catch unreachable) {
|
2018-05-01 08:35:54 +08:00
|
|
|
FormValue.Address => |payload| {
|
|
|
|
assert(payload == 1);
|
|
|
|
},
|
2017-04-24 07:59:55 +08:00
|
|
|
else => unreachable,
|
|
|
|
}
|
2016-09-23 14:00:23 +08:00
|
|
|
assert(read_count == 1);
|
|
|
|
}
|