contextual void construction
This commit is contained in:
@@ -58,6 +58,10 @@ payload_of :: func(d Data) i32 {
|
||||
return v
|
||||
}
|
||||
|
||||
make_box :: func() Box {
|
||||
return Box{ point = Point{ x = 4, y = 0 } }
|
||||
}
|
||||
|
||||
main :: func() i32 {
|
||||
acc i32 = 0
|
||||
|
||||
@@ -93,8 +97,8 @@ main :: func() i32 {
|
||||
}
|
||||
acc = acc + bucket # +5
|
||||
|
||||
# void-payload variant: bare-key construction + a no-capture arm
|
||||
e Box = Box{ empty }
|
||||
# void-payload variant: contextual construction (`.empty` coerces to Box) + no-capture arm
|
||||
e Box = .empty
|
||||
hit i32 = 0
|
||||
match e {
|
||||
.point |pt|: hit = pt.x
|
||||
@@ -110,6 +114,12 @@ main :: func() i32 {
|
||||
}
|
||||
acc = acc + b.point.x # +10 (mutated through the @mut Point)
|
||||
|
||||
# 50 + 47 + 3 + 2 + 5 + 7 + 10 = 124
|
||||
return acc - 124
|
||||
# match directly on a call result (no need to bind it to a variable first)
|
||||
match make_box() {
|
||||
.point |p|: acc = acc + p.x # +4
|
||||
.empty: hit = hit
|
||||
}
|
||||
|
||||
# 50 + 47 + 3 + 2 + 5 + 7 + 10 + 4 = 128
|
||||
return acc - 128
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user