mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
parent
70de4e1009
commit
0b843b801f
@ -321,7 +321,7 @@ fn C.WriteConsole() voidptr
|
|||||||
|
|
||||||
fn C.WriteFile() voidptr
|
fn C.WriteFile() voidptr
|
||||||
|
|
||||||
fn C._wchdir(dirname &u16)
|
fn C._wchdir(dirname &u16) int
|
||||||
|
|
||||||
fn C._wgetcwd(buffer &u16, maxlen int) int
|
fn C._wgetcwd(buffer &u16, maxlen int) int
|
||||||
|
|
||||||
|
@ -194,6 +194,14 @@ pub fn (mut c Checker) if_expr(mut node ast.IfExpr) ast.Type {
|
|||||||
node.typ = c.expected_type
|
node.typ = c.expected_type
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if last_expr.typ == ast.void_type && !is_noreturn_callexpr(last_expr.expr)
|
||||||
|
&& !c.skip_flags {
|
||||||
|
// cannot return void type and use it as expr in any circumstances
|
||||||
|
// (e.g. argument expression, variable declaration / assignment)
|
||||||
|
c.error('the final expression in `if` or `match`, must have a value of a non-void type',
|
||||||
|
last_expr.pos)
|
||||||
|
continue
|
||||||
|
}
|
||||||
if !c.check_types(last_expr.typ, node.typ) {
|
if !c.check_types(last_expr.typ, node.typ) {
|
||||||
if node.typ == ast.void_type {
|
if node.typ == ast.void_type {
|
||||||
// first branch of if expression
|
// first branch of if expression
|
||||||
|
@ -19,14 +19,21 @@ vlib/v/checker/tests/if_match_result.vv:7:3: error: `if` expression requires an
|
|||||||
8 | }
|
8 | }
|
||||||
9 |
|
9 |
|
||||||
vlib/v/checker/tests/if_match_result.vv:11:3: error: assignment mismatch: 1 variable(s) 0 value(s)
|
vlib/v/checker/tests/if_match_result.vv:11:3: error: assignment mismatch: 1 variable(s) 0 value(s)
|
||||||
9 |
|
9 |
|
||||||
10 | // void results
|
10 | // void results
|
||||||
11 | _ = match 4 {
|
11 | _ = match 4 {
|
||||||
| ^
|
| ^
|
||||||
12 | 1 {println('')}
|
12 | 1 { println('') }
|
||||||
13 | else {exit(0)}
|
13 | else { exit(0) }
|
||||||
|
vlib/v/checker/tests/if_match_result.vv:16:2: error: the final expression in `if` or `match`, must have a value of a non-void type
|
||||||
|
14 | }
|
||||||
|
15 | _ = if true {
|
||||||
|
16 | println('')
|
||||||
|
| ~~~~~~~~~~~
|
||||||
|
17 | } else {
|
||||||
|
18 | exit(0)
|
||||||
vlib/v/checker/tests/if_match_result.vv:15:3: error: assignment mismatch: 1 variable(s) 0 value(s)
|
vlib/v/checker/tests/if_match_result.vv:15:3: error: assignment mismatch: 1 variable(s) 0 value(s)
|
||||||
13 | else {exit(0)}
|
13 | else { exit(0) }
|
||||||
14 | }
|
14 | }
|
||||||
15 | _ = if true {
|
15 | _ = if true {
|
||||||
| ^
|
| ^
|
||||||
|
@ -9,8 +9,8 @@ _ = if true {
|
|||||||
|
|
||||||
// void results
|
// void results
|
||||||
_ = match 4 {
|
_ = match 4 {
|
||||||
1 {println('')}
|
1 { println('') }
|
||||||
else {exit(0)}
|
else { exit(0) }
|
||||||
}
|
}
|
||||||
_ = if true {
|
_ = if true {
|
||||||
println('')
|
println('')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user