From 626b73e8beeaae1cab23f883f877d89d64bbfa39 Mon Sep 17 00:00:00 2001
From: Andrew Kelley
Attempting to convert a number of bytes with a length that does not evenly divide into a slice of - elements results in {#link|Undefined Behavior#}. + elements results in safety-protected {#link|Undefined Behavior#}.
{#header_close#} @@ -4935,7 +4935,7 @@ test "main" {@errSetCast(comptime T: DestType, value: var) DestType
Converts an error value from one error set to another error set. Attempting to convert an error - which is not in the destination error set results in {#link|Undefined Behavior#}. + which is not in the destination error set results in safety-protected {#link|Undefined Behavior#}.
{#header_close#} @@ -4955,6 +4955,7 @@ test "main" { error name table will be generated. {#header_close#} + {#header_open|@errorReturnTrace#}@errorReturnTrace() ?*builtin.StackTrace
@@ -4964,6 +4965,25 @@ test "main" {
{#header_close#} + {#header_open|@errorToInt#} +@errorToInt(err: var) @IntType(false, @sizeOf(error) * 8)
+ + Supports the following types: +
+E!void+ Converts an error to the integer representation of an error. +
++ It is generally recommended to avoid this + cast, as the integer representation of an error is not stable across source code changes. +
+ {#see_also|@intToError#} + {#header_close#} + {#header_open|@export#}@export(comptime name: []const u8, target: var, linkage: builtin.GlobalLinkage) []const u8
@@ -5071,8 +5091,24 @@ fn add(a: i32, b: i32) i32 { return a + b; }
Converts an integer to another integer while keeping the same numerical value. Attempting to convert a number which is out of range of the destination type results in - {#link|Undefined Behavior#}. + safety-protected {#link|Undefined Behavior#}. +
+ {#header_close#} + + {#header_open|@intToError#} +@intToError(value: @IntType(false, @sizeOf(error) * 8)) error
+ + Converts from the integer representation of an error into the global error set type. +
++ It is generally recommended to avoid this + cast, as the integer representation of an error is not stable across source code changes. +
++ Attempting to convert an integer that does not correspond to any error results in + safety-protected {#link|Undefined Behavior#}.
+ {#see_also|@errorToInt#} {#header_close#} {#header_open|@intToFloat#} @@ -6123,8 +6159,8 @@ fn getNumberOrFail() !i32 { {#code_begin|test_err|integer value 11 represents no error#} comptime { const err = error.AnError; - const number = u32(err) + 10; - const invalid_err = error(number); + const number = @errorToInt(err) + 10; + const invalid_err = @intToError(number); } {#code_end#}At runtime crashes with the message invalid error code and a stack trace.