| 1 | const std = @import("std"); |
| 2 | const expectEqual = std.testing.expectEqual; |
| 3 | |
| 4 | test "comptime vars" { |
| 5 | var x: i32 = 1; |
| 6 | comptime var y: i32 = 1; |
| 7 | |
| 8 | x += 1; |
| 9 | y += 1; |
| 10 | |
| 11 | try expectEqual(2, x); |
| 12 | try expectEqual(2, y); |
| 13 | |
| 14 | if (y != 2) { |
| 15 | // This compile error never triggers because y is a comptime variable, |
| 16 | // and so `y != 2` is a comptime value, and this if is statically evaluated. |
| 17 | @compileError("wrong y value"); |
| 18 | } |
| 19 | } |
| 20 | |
| 21 | // test |