| ... | @@ -1276,3 +1276,35 @@ test "switch with advanced prong items" { | ... | @@ -1276,3 +1276,35 @@ test "switch with advanced prong items" { |
| 1276 | try S.doTheTest(); | 1276 | try S.doTheTest(); |
| 1277 | try comptime S.doTheTest(); | 1277 | try comptime S.doTheTest(); |
| 1278 | } | 1278 | } |
| | 1279 | |
| | 1280 | test "switch evaluation order" { |
| | 1281 | const eval = comptime eval: { |
| | 1282 | var eval = false; |
| | 1283 | const eu: anyerror!u32 = 0; |
| | 1284 | _ = eu catch |err| switch (err) { |
| | 1285 | blk: { |
| | 1286 | eval = true; |
| | 1287 | break :blk error.MyError; |
| | 1288 | } => {}, |
| | 1289 | else => unreachable, |
| | 1290 | }; |
| | 1291 | break :eval eval; |
| | 1292 | }; |
| | 1293 | try comptime expect(!eval); |
| | 1294 | } |
| | 1295 | |
| | 1296 | test "switch resolves lazy values correctly" { |
| | 1297 | const S = extern struct { |
| | 1298 | a: u16, |
| | 1299 | b: i16, |
| | 1300 | }; |
| | 1301 | const ok1 = switch (@sizeOf(S)) { |
| | 1302 | 4 => true, |
| | 1303 | else => false, |
| | 1304 | }; |
| | 1305 | const ok2 = switch (@sizeOf(S)) { |
| | 1306 | 4 => true, |
| | 1307 | else => false, |
| | 1308 | }; |
| | 1309 | try comptime expect(ok1 == ok2); |
| | 1310 | } |