remove error to/from int casting syntax; add @errorToInt/@intToError

See #1061
This commit is contained in:
Andrew Kelley
2018-06-18 18:48:29 -04:00
parent a430853a48
commit 626b73e8be
10 changed files with 138 additions and 60 deletions

View File

@@ -31,8 +31,8 @@ test "@errorName" {
}
test "error values" {
const a = i32(error.err1);
const b = i32(error.err2);
const a = @errorToInt(error.err1);
const b = @errorToInt(error.err2);
assert(a != b);
}
@@ -147,14 +147,14 @@ test "syntax: optional operator in front of error union operator" {
}
test "comptime err to int of error set with only 1 possible value" {
testErrToIntWithOnePossibleValue(error.A, u32(error.A));
comptime testErrToIntWithOnePossibleValue(error.A, u32(error.A));
testErrToIntWithOnePossibleValue(error.A, @errorToInt(error.A));
comptime testErrToIntWithOnePossibleValue(error.A, @errorToInt(error.A));
}
fn testErrToIntWithOnePossibleValue(
x: error{A},
comptime value: u32,
) void {
if (u32(x) != value) {
if (@errorToInt(x) != value) {
@compileError("bad");
}
}