From 78efe72c4cb9bc597c5b9ab6e62f081fb9aef22a Mon Sep 17 00:00:00 2001 From: yuyi Date: Thu, 7 May 2020 18:34:06 +0800 Subject: [PATCH] checker: optimize check string cast error --- vlib/v/checker/checker.v | 6 +----- vlib/v/checker/tests/cast_string_err.out | 2 +- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index bcb91efe4e..225548986d 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -1582,16 +1582,12 @@ pub fn (mut c Checker) expr(node ast.Expr) table.Type { if it.typ == table.string_type && !(sym.kind in [.byte, .byteptr] || sym.kind == .array && sym.name == 'array_byte') { type_name := c.table.type_to_str(it.expr_type) - c.error('cannot cast type `$type_name` to string', it.pos) + c.error('cannot cast type `$type_name` to string, use `x.str()` instead', it.pos) } if it.has_arg { c.expr(it.arg) } it.typname = c.table.get_type_symbol(it.typ).name - if it.typ == table.string_type && !it.has_arg && it.expr_type.is_number() && !it.expr_type.is_ptr() { - // s := c.table.get_type_symbol(it.expr_type) - c.error('use `number.str()` instead of `string(number)`', it.pos) - } return it.typ } ast.CallExpr { diff --git a/vlib/v/checker/tests/cast_string_err.out b/vlib/v/checker/tests/cast_string_err.out index 7edeabbf37..a5b128b429 100644 --- a/vlib/v/checker/tests/cast_string_err.out +++ b/vlib/v/checker/tests/cast_string_err.out @@ -1,4 +1,4 @@ -vlib/v/checker/tests/cast_string_err.v:2:14: error: cannot cast type `int` to string +vlib/v/checker/tests/cast_string_err.v:2:14: error: cannot cast type `int` to string, use `x.str()` instead 1 | fn main() { 2 | a := string(1) | ^