if statements support comptime known test error, runtime payload

This commit is contained in:
Andrew Kelley
2018-02-08 22:18:13 -05:00
parent 54c06bf715
commit 0efe441dfd
3 changed files with 16 additions and 29 deletions

View File

@@ -123,3 +123,14 @@ fn testExplicitErrorSetCast(set1: Set1) void {
var y = Set1(x);
assert(y == error.A);
}
test "comptime test error for empty error set" {
testComptimeTestErrorEmptySet(1234);
comptime testComptimeTestErrorEmptySet(1234);
}
const EmptyErrorSet = error {};
fn testComptimeTestErrorEmptySet(x: EmptyErrorSet!i32) void {
if (x) |v| assert(v == 1234) else |err| @compileError("bad");
}