mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: add a check for dump(c)
, where typeof(c) == "char"
This commit is contained in:
parent
78d9975798
commit
9bbb52e9cc
@ -2603,10 +2603,16 @@ pub fn (mut c Checker) expr(node_ ast.Expr) ast.Type {
|
||||
}
|
||||
ast.DumpExpr {
|
||||
node.expr_type = c.expr(node.expr)
|
||||
if node.expr_type.idx() == ast.void_type_idx {
|
||||
etidx := node.expr_type.idx()
|
||||
if etidx == ast.void_type_idx {
|
||||
c.error('dump expression can not be void', node.expr.pos())
|
||||
return ast.void_type
|
||||
} else if etidx == ast.char_type_idx && node.expr_type.nr_muls() == 0 {
|
||||
c.error('`char` values cannot be dumped directly, use dump(byte(x)) or dump(int(x)) instead',
|
||||
node.expr.pos())
|
||||
return ast.void_type
|
||||
}
|
||||
|
||||
tsym := c.table.sym(node.expr_type)
|
||||
c.table.dumps[int(node.expr_type)] = tsym.cname
|
||||
node.cname = tsym.cname
|
||||
|
5
vlib/v/checker/tests/dump_char.out
Normal file
5
vlib/v/checker/tests/dump_char.out
Normal file
@ -0,0 +1,5 @@
|
||||
vlib/v/checker/tests/dump_char.vv:3:6: error: `char` values cannot be dumped directly, use dump(byte(x)) or dump(int(x)) instead
|
||||
1 | c := char(67)
|
||||
2 | dump(byte(c))
|
||||
3 | dump(c)
|
||||
| ^
|
3
vlib/v/checker/tests/dump_char.vv
Normal file
3
vlib/v/checker/tests/dump_char.vv
Normal file
@ -0,0 +1,3 @@
|
||||
c := char(67)
|
||||
dump(byte(c))
|
||||
dump(c)
|
Loading…
Reference in New Issue
Block a user