fix: semantic restrictions for global variables, constant folding

This commit is contained in:
Brett Broadhurst 2026-03-28 11:00:07 -06:00
parent cbcc796f1e
commit 9b5cd4038f
Failed to generate hash of commit
13 changed files with 569 additions and 375 deletions

View file

@ -68,6 +68,29 @@ test "compiler: invalid divert target" {
);
}
test "compiler: global variable restrictions" {
try testEqual(
\\VAR a = b
\\VAR b = a
,
\\<STDIN>:1:9: error: global variable assignments cannot refer to other variables
\\1 | VAR a = b
\\ | ^
\\
);
}
test "compiler: constant cycle detection" {
try testEqual(
\\CONST a = a
,
\\<STDIN>:1:11: error: cycle detected in constant initializer
\\1 | CONST a = a
\\ | ^
\\
);
}
fn testEqual(source_bytes: [:0]const u8, expected_error: []const u8) !void {
const gpa = std.testing.allocator;
var arena_allocator = std.heap.ArenaAllocator.init(gpa);