anonymous struct payloads

This commit is contained in:
2026-06-30 23:01:18 +02:00
parent eb06b2ee62
commit d6f9c24314
6 changed files with 317 additions and 38 deletions
+23 -9
View File
@@ -5,6 +5,10 @@ BasicError :: enum {
DetailError :: union(enum) {
code i32
info struct {
code i32
extra i32
}
empty void
}
@@ -44,6 +48,7 @@ via_try func(value i32) i32 ! BasicError {
with_detail func(value i32) i32 ! DetailError {
if (value == 0) return .code{5}
if (value == 1) return .empty
if (value == 3) return .info{code = 8, extra = 9}
return value
}
@@ -65,8 +70,9 @@ catch_basic func(value i32) i32 {
catch_detail func(value i32) i32 {
return with_detail(value) catch |e| {
match e {
.code |n|: yield n + 30
.empty: yield 40
.code |n|: yield n + 30
.info |info|: yield info.code + info.extra + 30
.empty: yield 40
}
}
}
@@ -74,10 +80,11 @@ catch_detail func(value i32) i32 {
catch_widen func(value i32) i32 {
return via_widen(value) catch |e| {
match e {
.bad: yield 50
.worse: yield 51
.code |n|: yield n
.empty: yield 52
.bad: yield 50
.worse: yield 51
.code |n|: yield n
.info |info|: yield info.code + info.extra
.empty: yield 52
}
}
}
@@ -143,8 +150,15 @@ main func() i32 {
.inline_empty: yield 80
}
}
p :: with_detail(3) catch |e| {
match e {
.code |value|: yield value
.info |info|: yield info.code + info.extra
.empty: yield 0
}
}
acc = acc + a + b + c + d + e + f + g + h + i + j + k + l + m + n + o
acc = acc + a + b + c + d + e + f + g + h + i + j + k + l + m + n + o + p
acc = acc + pick(.left)
r Right = .right
acc = acc + pick(r)
@@ -154,6 +168,6 @@ main func() i32 {
acc = acc + payload(empty)
acc = acc + payload(.a{9})
# 7 + 5 + 5 + 11 + 13 + 2 + 21 + 22 + 35 + 40 + 6 + 50 + 51 + 60 + 76 + 10 + 20 + 8 + 3 + 9 = 454
return acc - 454
# 7 + 5 + 5 + 11 + 13 + 2 + 21 + 22 + 35 + 40 + 6 + 50 + 51 + 60 + 76 + 17 + 10 + 20 + 8 + 3 + 9 = 471
return acc - 471
}