mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
This commit is contained in:
parent
b83dd86d65
commit
b0e7ddfd97
@ -47,8 +47,8 @@ pub fn (mut c Checker) if_expr(mut node ast.IfExpr) ast.Type {
|
||||
// check condition type is boolean
|
||||
c.expected_type = ast.bool_type
|
||||
cond_typ := c.unwrap_generic(c.expr(branch.cond))
|
||||
if (cond_typ.idx() != ast.bool_type_idx || cond_typ.has_flag(.optional))
|
||||
&& !c.pref.translated && !c.file.is_translated {
|
||||
if (cond_typ.idx() != ast.bool_type_idx || cond_typ.has_flag(.optional)
|
||||
|| cond_typ.has_flag(.result)) && !c.pref.translated && !c.file.is_translated {
|
||||
c.error('non-bool type `${c.table.type_to_str(cond_typ)}` used as if condition',
|
||||
branch.cond.pos())
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
vlib/v/checker/tests/if_expr_optional_err.vv:7:5: error: non-bool type `?bool` used as if condition
|
||||
vlib/v/checker/tests/if_expr_optional_err.vv:6:5: error: non-bool type `?bool` used as if condition
|
||||
4 |
|
||||
5 | fn main() {
|
||||
6 |
|
||||
7 | if get_bool() {
|
||||
6 | if get_bool() {
|
||||
| ~~~~~~~~~~
|
||||
8 | println("Using plain lists")
|
||||
9 | }
|
||||
7 | println("Using plain lists")
|
||||
8 | }
|
@ -3,7 +3,6 @@ fn get_bool() ?bool {
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
||||
if get_bool() {
|
||||
println("Using plain lists")
|
||||
}
|
||||
|
7
vlib/v/checker/tests/if_expr_result_err.out
Normal file
7
vlib/v/checker/tests/if_expr_result_err.out
Normal file
@ -0,0 +1,7 @@
|
||||
vlib/v/checker/tests/if_expr_result_err.vv:6:5: error: non-bool type `!bool` used as if condition
|
||||
4 |
|
||||
5 | fn main() {
|
||||
6 | if get_bool() {
|
||||
| ~~~~~~~~~~
|
||||
7 | println("Using plain lists")
|
||||
8 | }
|
9
vlib/v/checker/tests/if_expr_result_err.vv
Normal file
9
vlib/v/checker/tests/if_expr_result_err.vv
Normal file
@ -0,0 +1,9 @@
|
||||
fn get_bool() !bool {
|
||||
return true
|
||||
}
|
||||
|
||||
fn main() {
|
||||
if get_bool() {
|
||||
println("Using plain lists")
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user