1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

checker: do not allow casting strings

This commit is contained in:
Alexander Medvednikov 2020-05-16 22:52:41 +02:00
parent 6e4ae5a5e6
commit 5b15b8ccc9

View File

@ -1687,7 +1687,14 @@ pub fn (mut c Checker) expr(node ast.Expr) table.Type {
c.error('cannot cast type `$type_name` to string, use `x.str()` instead', it.pos)
}
if it.expr_type == table.string_type {
c.error('cannot cast a string', it.pos)
mut error_msg := 'cannot cast a string'
if it.expr is ast.StringLiteral {
str_lit := it.expr as ast.StringLiteral
if str_lit.val.len == 1 {
error_msg += ", for denoting characters use `$str_lit.val` instead of '$str_lit.val'"
}
}
c.error(error_msg, it.pos)
}
if it.has_arg {
c.expr(it.arg)