mutable decl syntax change

This commit is contained in:
2026-08-05 21:19:41 +02:00
parent 88b94197c9
commit 081a3fd5df
74 changed files with 870 additions and 733 deletions
+9 -9
View File
@@ -7,7 +7,7 @@
# The return value is captured before defers run, so the mutation here does not
# change what is returned (Zig semantics).
spill_check func() i32 {
x i32 = 5
x i32 := 5
defer x = 999
return x
}
@@ -15,7 +15,7 @@ spill_check func() i32 {
# A function-scope defer runs only at function exit; a `break` runs the loop-body
# defer but NOT the enclosing function-scope defer.
enclosing_defer_check func() i32 {
v i32 = 0
v i32 := 0
defer v = v + 100
for 0..3 |i| {
defer v = v + 1
@@ -89,7 +89,7 @@ main func() i32 {
if (spill_check() != 5) return 101
# 2. LIFO ordering, run at end of each loop iteration.
r i32 = 0
r i32 := 0
for 0..1 |i| {
defer r = r * 2 + 1 # registered first -> runs last
defer r = r * 2 # registered second -> runs first
@@ -99,16 +99,16 @@ main func() i32 {
# 3. scoped bare block + scoped defer (defer fires at the closing brace, and
# the block-local is not visible afterwards).
a i32 = 1
a i32 := 1
{
defer a = 4
c i32 = 3
c i32 := 3
_ = c
}
if (a != 4) return 103
# 4. `defer { ... }` block: all its statements run (in order) at scope close.
s i32 = 0
s i32 := 0
{
defer {
s = s + 1
@@ -119,7 +119,7 @@ main func() i32 {
if (s != 60) return 104 # 5 -> 6 -> 60
# 5. `break` flushes the loop-body defer.
bc i32 = 0
bc i32 := 0
for 0..5 |i| {
defer bc = bc + 1
if (i == 2) break
@@ -127,7 +127,7 @@ main func() i32 {
if (bc != 3) return 105 # i=0,1 fall-through + i=2 break
# 6. `continue` flushes the loop-body defer.
cc i32 = 0
cc i32 := 0
for 0..3 |i| {
defer cc = cc + 1
if (i == 1) continue
@@ -139,7 +139,7 @@ main func() i32 {
if (enclosing_defer_check() != 2) return 107
# 8. errdefer is skipped on success; ordinary defers stay interleaved.
trace i32 = 0
trace i32 := 0
if ((explicit_cleanup(false, &trace) catch 0) != 7 or trace != 31) return 108
# 9. Explicit errors run errdefer and expose the captured error.