alex

/

v Public
0 Issues 1 Contributor 0 Releases 4 Branches
Additions: 27 Deletions: 3 View patch
1 }
2 } else if expr is ast.CastExpr {
3 c.check_expr_opt_call(expr.expr, ret_type)
4+ } else if expr is ast.AsCast {
5+ c.check_expr_opt_call(expr.expr, ret_type)
6 }
7 return ret_type
8 }
9 }
10 return
11 }
12-
13 if node.stmts.len == 0 {
14 if ret_type != ast.void_type {
15 // x := f() or {}
16 }
17 }
18 else {
19- if stmt.typ == ast.void_type {
20+ if stmt.typ == ast.void_type || expr_return_type == ast.void_type {
21 return
22 }
23 if is_noreturn_callexpr(stmt.expr) {
24
1new file mode 100644
2+vlib/v/checker/tests/as_cast_option_result_unhandled_err.vv:11:6: error: ret_sum_result() returns a result, so it should have either an `or {}` block, or `!` at the end
3+ 9 | }
4+ 10 |
5+ 11 | _ := ret_sum_result() as int
6+ | ~~~~~~~~~~~~~~~~
7+ 12 | _ := ret_sum_option() as string
8+vlib/v/checker/tests/as_cast_option_result_unhandled_err.vv:12:6: error: ret_sum_option() returns an option, so it should have either an `or {}` block, or `?` at the end
9+ 10 |
10+ 11 | _ := ret_sum_result() as int
11+ 12 | _ := ret_sum_option() as string
12+ | ~~~~~~~~~~~~~~~~
13
1new file mode 100644
2+type Sum = int | string
3+
4+fn ret_sum_result() !Sum {
5+ return 0
6+}
7+
8+fn ret_sum_option() ?Sum {
9+ return '0'
10+}
11+
12+_ := ret_sum_result() as int
13+_ := ret_sum_option() as string
14
1 pub fn (mut e Eval) eval(mut files []&ast.File) {
2 e.register_symbols(mut files)
3 // println(files.map(it.path_base))
4- e.run_func(e.mods['main']['main'] or { ast.EmptyStmt{} } as ast.FnDecl)
5+ e.run_func(e.mods['main']['main'] or { ast.FnDecl{} } as ast.FnDecl)
6 }
7
8 // first arg is reciever (if method)
9