checker: report correct position for non-bool cond error (#8735)
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)
|
cond_typ := c.expr(branch.cond)
|
||||||
if cond_typ.idx() != table.bool_type_idx && !c.pref.translated {
|
if cond_typ.idx() != table.bool_type_idx && !c.pref.translated {
|
||||||
typ_sym := c.table.get_type_symbol(cond_typ)
|
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() {
|
1 | fn main() {
|
||||||
2 | if '10' {
|
2 | if '10' {
|
||||||
| ~~~~~~~
|
| ~~~~
|
||||||
3 | println('10')
|
3 | println('10')
|
||||||
4 | }
|
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 | }
|
4 | }
|
||||||
5 |
|
5 |
|
||||||
6 | if 5 {
|
6 | if 5 {
|
||||||
| ~~~~
|
| ^
|
||||||
7 | println(5)
|
7 | println(5)
|
||||||
8 | }
|
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 | }
|
8 | }
|
||||||
9 |
|
9 |
|
||||||
10 | if println('v') {
|
10 | if println('v') {
|
||||||
| ~~~~~~~~~~~~~~~
|
| ~~~~~~~~~~~~
|
||||||
11 | println('println')
|
11 | println('println')
|
||||||
12 | }
|
12 | }
|
||||||
|
|
Loading…
Reference in New Issue