From 87a0765ce4f47bd998a2dada11ac832aebf67487 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Sun, 12 Jul 2020 19:46:33 +0300 Subject: [PATCH] doc: add that `or` blocks may end with default values --- doc/docs.md | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/doc/docs.md b/doc/docs.md index 013915c980..51bdd0733c 100644 --- a/doc/docs.md +++ b/doc/docs.md @@ -1373,8 +1373,14 @@ fn (r Repo) find_user_by_id(id int) ?User { fn main() { repo := new_repo() - user := repo.find_user_by_id(10) or { // Option types must be handled by `or` blocks - return // `or` block must end with `return`, `break`, or `continue` + user := repo.find_user_by_id(10) or { + // Option types must be handled by `or` blocks. + // Any `or` block, *must* end with one of: + // a) `break`, `continue` or `return` . + // b) a panic("message") or exit(code) call . + // c) a default value of the same type as the Option . + // (i.e. if the function returns for example ?int, you may put 1234 as default value) + return } println(user.id) // "10" println(user.name) // "Charles"