File tree Expand file tree Collapse file tree 2 files changed +26
-1
lines changed Expand file tree Collapse file tree 2 files changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -327,7 +327,7 @@ fn (mut c Checker) if_expr(mut node ast.IfExpr) ast.Type {
327
327
node.pos)
328
328
}
329
329
}
330
- } else if ! node.is_comptime {
330
+ } else if ! node.is_comptime && stmt ! is ast.Return {
331
331
c.error ('`${if_kind} ` expression requires an expression as the last statement of every branch' ,
332
332
branch.pos)
333
333
}
Original file line number Diff line number Diff line change
1
+ struct NotFoundError {
2
+ Error
3
+ }
4
+
5
+ fn get_username () ! string {
6
+ return NotFoundError{}
7
+ }
8
+
9
+ fn print_username () ! string {
10
+ username := get_username () or {
11
+ if err is NotFoundError {
12
+ 'test'
13
+ } else {
14
+ return err
15
+ }
16
+ }
17
+
18
+ println (username)
19
+ return username
20
+ }
21
+
22
+ fn test_return_err_in_if_expr () {
23
+ ret := print_username ()!
24
+ assert ret == 'test'
25
+ }
You can’t perform that action at this time.
0 commit comments