diff --git a/doc/langref.html.in b/doc/langref.html.in index d047c7d9f2..c3c50b117b 100644 --- a/doc/langref.html.in +++ b/doc/langref.html.in @@ -3111,7 +3111,48 @@ test "error union" { {#code_end#}
TODO the || operator for error sets
TODO
++ Because many functions in Zig return a possible error, Zig supports inferring the error set. + To infer the error set for a function, use this syntax: +
+{#code_begin|test#} +// With an inferred error set +pub fn add_inferred(comptime T: type, a: T, b: T) !T { + var answer: T = undefined; + return if (@addWithOverflow(T, a, b, &answer)) error.Overflow else answer; +} + +// With an explicit error set +pub fn add_explicit(comptime T: type, a: T, b: T) Error!T { + var answer: T = undefined; + return if (@addWithOverflow(T, a, b, &answer)) error.Overflow else answer; +} + +const Error = error { + Overflow, +}; + +const std = @import("std"); + +test "inferred error set" { + if (add_inferred(u8, 255, 1)) |_| unreachable else |err| switch (err) { + error.Overflow => {}, // ok + } +} +{#code_end#} ++ When a function has an inferred error set, that function becomes generic and thus it becomes + trickier to do certain things with it, such as obtain a function pointer, or have an error + set that is consistent across different build targets. Additionally, inferred error sets + are incompatible with recursion. +
++ In these situations, it is recommended to use an explicit error set. You can generally start + with an empty error set and let compile errors guide you toward completing the set. +
++ These limitations may be overcome in a future version of Zig. +
{#header_close#} {#header_close#} {#header_open|Error Return Traces#} @@ -3878,7 +3919,16 @@ pub fn main() void { {#header_close#} {#header_open|@ArgType#} -TODO
+@ArgType(comptime T: type, comptime n: usize) -> type
+
+ This builtin function takes a function type and returns the type of the parameter at index n.
+
+ T must be a function type.
+
+ Note: This function is deprecated. Use {#link|@typeInfo#} instead. +
{#header_close#} {#header_open|@atomicLoad#}@atomicLoad(comptime T: type, ptr: &const T, comptime ordering: builtin.AtomicOrder) -> T