From 5b15b8ccc9e4368620fedded0db173a887ffe0f3 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Sat, 16 May 2020 22:52:41 +0200 Subject: [PATCH] checker: do not allow casting strings --- vlib/v/checker/checker.v | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index 7df8b30776..10596f0d98 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -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)