contextual payload construction

This commit is contained in:
2026-06-30 21:14:59 +02:00
parent 7ca7e33033
commit 5161e99af5
5 changed files with 450 additions and 85 deletions
+37 -5
View File
@@ -42,7 +42,7 @@ via_try func(value i32) i32 ! BasicError {
}
with_detail func(value i32) i32 ! DetailError {
if (value == 0) return DetailError{ code = 5 }
if (value == 0) return .code{5}
if (value == 1) return .empty
return value
}
@@ -96,6 +96,24 @@ payload func(value Box) i32 {
}
}
inline_enum func(value i32) i32 ! enum {
inline_bad
inline_worse
} {
if (value == 0) return .inline_bad
if (value < 0) return .inline_worse
return value
}
inline_detail func(value i32) i32 ! union(enum) {
inline_code i32
inline_empty void
} {
if (value == 0) return .inline_code{6}
if (value == 1) return .inline_empty
return value
}
main func() i32 {
acc i32 = 0
@@ -112,16 +130,30 @@ main func() i32 {
k :: via_widen(3) catch 99
l :: catch_widen(0)
m :: catch_widen(-1)
n :: inline_enum(0) catch |e| {
if (e == .inline_bad) {
yield 60
} else {
yield 61
}
}
o :: inline_detail(0) catch |e| {
match e {
.inline_code |value|: yield value + 70
.inline_empty: yield 80
}
}
acc = acc + a + b + c + d + e + f + g + h + i + j + k + l + m
acc = acc + a + b + c + d + e + f + g + h + i + j + k + l + m + n + o
acc = acc + pick(.left)
r Right = .right
acc = acc + pick(r)
box BoxA = BoxA{ a = 8 }
box BoxA = .a{8}
acc = acc + payload(box)
empty BoxB = .b
acc = acc + payload(empty)
acc = acc + payload(.a{9})
# 7 + 5 + 5 + 11 + 13 + 2 + 21 + 22 + 35 + 40 + 6 + 50 + 51 + 10 + 20 + 8 + 3 = 309
return acc - 309
# 7 + 5 + 5 + 11 + 13 + 2 + 21 + 22 + 35 + 40 + 6 + 50 + 51 + 60 + 76 + 10 + 20 + 8 + 3 + 9 = 454
return acc - 454
}