zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

test_merging_error_sets.zig (470B) - Raw


      1 const A = error{
      2     NotDir,
      3 
      4     /// A doc comment
      5     PathNotFound,
      6 };
      7 const B = error{
      8     OutOfMemory,
      9 
     10     /// B doc comment
     11     PathNotFound,
     12 };
     13 
     14 const C = A || B;
     15 
     16 fn foo() C!void {
     17     return error.NotDir;
     18 }
     19 
     20 test "merge error sets" {
     21     if (foo()) {
     22         @panic("unexpected");
     23     } else |err| switch (err) {
     24         error.OutOfMemory => @panic("unexpected"),
     25         error.PathNotFound => @panic("unexpected"),
     26         error.NotDir => {},
     27     }
     28 }
     29 
     30 // test