mirror of
https://github.com/ziglang/zig.git
synced 2024-11-30 09:02:32 +00:00
22 lines
450 B
Zig
22 lines
450 B
Zig
const std = @import("std");
|
|
const expect = std.testing.expect;
|
|
|
|
test "comptime vars" {
|
|
var x: i32 = 1;
|
|
comptime var y: i32 = 1;
|
|
|
|
x += 1;
|
|
y += 1;
|
|
|
|
try expect(x == 2);
|
|
try expect(y == 2);
|
|
|
|
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
|