diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index 81a5366d2e..84614732f0 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -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 diff --git a/vlib/v/checker/tests/dump_char.out b/vlib/v/checker/tests/dump_char.out new file mode 100644 index 0000000000..e91da864f1 --- /dev/null +++ b/vlib/v/checker/tests/dump_char.out @@ -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) + | ^ diff --git a/vlib/v/checker/tests/dump_char.vv b/vlib/v/checker/tests/dump_char.vv new file mode 100644 index 0000000000..84a6354ab5 --- /dev/null +++ b/vlib/v/checker/tests/dump_char.vv @@ -0,0 +1,3 @@ +c := char(67) +dump(byte(c)) +dump(c)