| 1 | const S = struct { x: u32 = 0 }; |
| 2 | const T = struct { []const u8 }; |
| 3 | |
| 4 | fn test0() !void { |
| 5 | const x: u8 = try 1; |
| 6 | _ = x; |
| 7 | } |
| 8 | |
| 9 | fn test1() !void { |
| 10 | const x: S = try .{}; |
| 11 | _ = x; |
| 12 | } |
| 13 | |
| 14 | fn test2() !void { |
| 15 | const x: S = try S{ .x = 123 }; |
| 16 | _ = x; |
| 17 | } |
| 18 | |
| 19 | fn test3() !void { |
| 20 | const x: S = try try S{ .x = 123 }; |
| 21 | _ = x; |
| 22 | } |
| 23 | |
| 24 | fn test4() !void { |
| 25 | const x: T = try .{"hello"}; |
| 26 | _ = x; |
| 27 | } |
| 28 | |
| 29 | fn test5() !void { |
| 30 | const x: error{Foo}!u32 = 123; |
| 31 | _ = try try x; |
| 32 | } |
| 33 | |
| 34 | comptime { |
| 35 | _ = &test0; |
| 36 | _ = &test1; |
| 37 | _ = &test2; |
| 38 | _ = &test3; |
| 39 | _ = &test4; |
| 40 | _ = &test5; |
| 41 | } |
| 42 | |
| 43 | // error |
| 44 | // |
| 45 | // :5:23: error: expected error union type, found 'comptime_int' |
| 46 | // :5:23: note: consider omitting 'try' |
| 47 | // :10:23: error: expected error union type, found '@TypeOf(.{})' |
| 48 | // :10:23: note: consider omitting 'try' |
| 49 | // :15:23: error: expected error union type, found 'tmp.S' |
| 50 | // :1:11: note: struct declared here |
| 51 | // :15:23: note: consider omitting 'try' |
| 52 | // :20:27: error: expected error union type, found 'tmp.S' |
| 53 | // :1:11: note: struct declared here |
| 54 | // :20:27: note: consider omitting 'try' |
| 55 | // :25:23: error: expected error union type, found 'struct { comptime *const [5:0]u8 = "hello" }' |
| 56 | // :25:23: note: consider omitting 'try' |
| 57 | // :31:13: error: expected error union type, found 'u32' |
| 58 | // :31:13: note: consider omitting 'try' |