mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: report correct position for non-bool cond error (#8735)
This commit is contained in:
parent
82650ee813
commit
e534b4397d
@ -4757,7 +4757,7 @@ pub fn (mut c Checker) if_expr(mut node ast.IfExpr) table.Type {
|
||||
cond_typ := c.expr(branch.cond)
|
||||
if cond_typ.idx() != table.bool_type_idx && !c.pref.translated {
|
||||
typ_sym := c.table.get_type_symbol(cond_typ)
|
||||
c.error('non-bool type `$typ_sym.name` used as if condition', branch.pos)
|
||||
c.error('non-bool type `$typ_sym.name` used as if condition', branch.cond.position())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,20 +1,20 @@
|
||||
vlib/v/checker/tests/if_non_bool_cond.vv:2:2: error: non-bool type `string` used as if condition
|
||||
vlib/v/checker/tests/if_non_bool_cond.vv:2:5: error: non-bool type `string` used as if condition
|
||||
1 | fn main() {
|
||||
2 | if '10' {
|
||||
| ~~~~~~~
|
||||
| ~~~~
|
||||
3 | println('10')
|
||||
4 | }
|
||||
vlib/v/checker/tests/if_non_bool_cond.vv:6:2: error: non-bool type `int literal` used as if condition
|
||||
vlib/v/checker/tests/if_non_bool_cond.vv:6:5: error: non-bool type `int literal` used as if condition
|
||||
4 | }
|
||||
5 |
|
||||
6 | if 5 {
|
||||
| ~~~~
|
||||
| ^
|
||||
7 | println(5)
|
||||
8 | }
|
||||
vlib/v/checker/tests/if_non_bool_cond.vv:10:2: error: non-bool type `void` used as if condition
|
||||
vlib/v/checker/tests/if_non_bool_cond.vv:10:5: error: non-bool type `void` used as if condition
|
||||
8 | }
|
||||
9 |
|
||||
10 | if println('v') {
|
||||
| ~~~~~~~~~~~~~~~
|
||||
| ~~~~~~~~~~~~
|
||||
11 | println('println')
|
||||
12 | }
|
||||
|
Loading…
Reference in New Issue
Block a user