Unknown state [2025-08-04]

This commit is contained in:
2025-08-04 22:23:16 -04:00
parent a145a60fa8
commit bc4b577d6f
4 changed files with 160 additions and 0 deletions

View File

@@ -0,0 +1,11 @@
const std = @import("std");
pub fn main() !void {
var i: usize = 0;
while (i < 10) {
i += 1;
if (i % 2 == 0)
continue;
std.debug.print("foo {d}\n", .{i});
}
}

View File

@@ -0,0 +1,8 @@
const std = @import("std");
pub fn main() void {
acquire: while (true) {
continue :acquire;
break :acquire;
}
}

View File

@@ -0,0 +1,42 @@
const std = @import("std");
const Data = enum { foo, bar };
pub fn optional_enum_error_union() !?Data {
const state = struct {
var flag: u2 = 0;
};
defer state.flag +%= 1;
return switch (state.flag) {
0 => null,
1 => .foo,
2 => .bar,
3 => error.Fizz,
};
}
pub fn main() !void {
for (0..4) |_| {
const r1 = if (optional_enum_error_union()) |opt|
if (opt) |val|
switch (val) {
.foo => "FOO",
.bar => "BAR",
}
else
"NULL"
else |err| switch (err) {
error.Fizz => "FIZZ",
else => return err,
};
const r2 = switch (optional_enum_error_union()) {
.foo => "FOO",
.bar => "BAR",
null => "NULL",
error.Fizz => "FIZZ",
anyerror => |err| return err,
};
}
}