parser, checker: check assert optional (#10319)
parent
04642211b4
commit
1747e546bf
|
@ -4064,7 +4064,7 @@ fn (mut c Checker) stmt(node ast.Stmt) {
|
||||||
fn (mut c Checker) assert_stmt(node ast.AssertStmt) {
|
fn (mut c Checker) assert_stmt(node ast.AssertStmt) {
|
||||||
cur_exp_typ := c.expected_type
|
cur_exp_typ := c.expected_type
|
||||||
assert_type := c.check_expr_opt_call(node.expr, c.expr(node.expr))
|
assert_type := c.check_expr_opt_call(node.expr, c.expr(node.expr))
|
||||||
if assert_type != ast.bool_type_idx && assert_type != ast.void_type_idx {
|
if assert_type != ast.bool_type_idx {
|
||||||
atype_name := c.table.get_type_symbol(assert_type).name
|
atype_name := c.table.get_type_symbol(assert_type).name
|
||||||
c.error('assert can be used only with `bool` expressions, but found `$atype_name` instead',
|
c.error('assert can be used only with `bool` expressions, but found `$atype_name` instead',
|
||||||
node.pos)
|
node.pos)
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
vlib/v/checker/tests/assert_optional_err.vv:4:9: error: assert can be used only with `bool` expressions, but found `void` instead
|
||||||
|
2 |
|
||||||
|
3 | fn main(){
|
||||||
|
4 | assert os.truncate("testfile.txt", 6666) or { panic(err) }
|
||||||
|
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
5 | }
|
|
@ -0,0 +1,5 @@
|
||||||
|
import os
|
||||||
|
|
||||||
|
fn main(){
|
||||||
|
assert os.truncate("testfile.txt", 6666) or { panic(err) }
|
||||||
|
}
|
|
@ -685,7 +685,7 @@ pub fn (mut p Parser) stmt(is_top_level bool) ast.Stmt {
|
||||||
pos.update_last_line(p.prev_tok.line_nr)
|
pos.update_last_line(p.prev_tok.line_nr)
|
||||||
return ast.AssertStmt{
|
return ast.AssertStmt{
|
||||||
expr: expr
|
expr: expr
|
||||||
pos: pos
|
pos: pos.extend(p.tok.position())
|
||||||
is_used: p.inside_test_file || !p.pref.is_prod
|
is_used: p.inside_test_file || !p.pref.is_prod
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue