aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2021-08-15 18:51:20 +0100
committergingerBill <bill@gingerbill.org>2021-08-15 18:51:20 +0100
commit3e2788afdcb3e846caea261ab04d15a19909a2ed (patch)
treeab271ec4b54d2f004dc5d2ca315a532169c4e35d
parent1a7f508dd94671b8575ee9decabf5ec9a52777c2 (diff)
Add extra example to `or_return_operator`
-rw-r--r--examples/demo/demo.odin8
1 files changed, 7 insertions, 1 deletions
diff --git a/examples/demo/demo.odin b/examples/demo/demo.odin
index d896e4eb5..bf3620388 100644
--- a/examples/demo/demo.odin
+++ b/examples/demo/demo.odin
@@ -2055,6 +2055,9 @@ or_return_operator :: proc() {
caller_2 :: proc() -> (int, Error) {
return 123, .None;
}
+ caller_3 :: proc() -> (int, int, Error) {
+ return 123, 345, .None;
+ }
foo_1 :: proc() -> Error {
// This can be a common idiom in many code bases
@@ -2074,7 +2077,10 @@ or_return_operator :: proc() {
return err1;
}
- _, _ = n0, n1;
+ // Multiple return values still work with 'or_return' as it only
+ // pops off the end value in the multi-valued expression
+ n0, n1 = caller_3() or_return;
+
return .None;
}
foo_2 :: proc() -> (n: int, err: Error) {