mirror of
https://codeberg.org/ziglang/zig.git
synced 2026-03-08 02:44:43 +01:00
21 lines
466 B
Zig
21 lines
466 B
Zig
const std = @import("std");
|
|
const expectEqual = std.testing.expectEqual;
|
|
|
|
test "comptime vars" {
|
|
var x: i32 = 1;
|
|
comptime var y: i32 = 1;
|
|
|
|
x += 1;
|
|
y += 1;
|
|
|
|
try expectEqual(2, x);
|
|
try expectEqual(2, y);
|
|
|
|
if (y != 2) {
|
|
// This compile error never triggers because y is a comptime variable,
|
|
// and so `y != 2` is a comptime value, and this if is statically evaluated.
|
|
@compileError("wrong y value");
|
|
}
|
|
}
|
|
|
|
// test
|