checker: add a check for `dump(c)`, where `typeof(c) == "char"`
							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 | ||||
|  |  | |||
|  | @ -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) | ||||
|       |      ^ | ||||
|  | @ -0,0 +1,3 @@ | |||
| c := char(67) | ||||
| dump(byte(c)) | ||||
| dump(c) | ||||
		Loading…
	
		Reference in New Issue