File tree Expand file tree Collapse file tree 1 file changed +8
-2
lines changed Expand file tree Collapse file tree 1 file changed +8
-2
lines changed Original file line number Diff line number Diff line change @@ -1373,8 +1373,14 @@ fn (r Repo) find_user_by_id(id int) ?User {
1373
1373
1374
1374
fn main() {
1375
1375
repo := new_repo()
1376
- user := repo.find_user_by_id(10) or { // Option types must be handled by `or` blocks
1377
- return // `or` block must end with `return`, `break`, or `continue`
1376
+ user := repo.find_user_by_id(10) or {
1377
+ // Option types must be handled by `or` blocks.
1378
+ // Any `or` block, *must* end with one of:
1379
+ // a) `break`, `continue` or `return` .
1380
+ // b) a panic("message") or exit(code) call .
1381
+ // c) a default value of the same type as the Option .
1382
+ // (i.e. if the function returns for example ?int, you may put 1234 as default value)
1383
+ return
1378
1384
}
1379
1385
println(user.id) // "10"
1380
1386
println(user.name) // "Charles"
You can’t perform that action at this time.
0 commit comments