mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
This commit is contained in:
parent
8b962f8446
commit
566a61b136
@ -2506,6 +2506,10 @@ pub fn (mut c Checker) cast_expr(mut node ast.CastExpr) ast.Type {
|
||||
snexpr := node.expr.str()
|
||||
tt := c.table.type_to_str(to_type)
|
||||
c.error('cannot cast string to `$tt`, use `${snexpr}.str` instead.', node.pos)
|
||||
} else if final_from_sym.kind == .string && to_sym.kind == .char {
|
||||
snexpr := node.expr.str()
|
||||
tt := c.table.type_to_str(to_type)
|
||||
c.error('cannot cast string to `$tt`, use `$snexpr[index]` instead.', node.pos)
|
||||
} else if final_from_sym.kind == .array && !from_type.is_ptr() && to_type != ast.string_type {
|
||||
ft := c.table.type_to_str(from_type)
|
||||
tt := c.table.type_to_str(to_type)
|
||||
|
5
vlib/v/checker/tests/cast_string_to_char_err.out
Normal file
5
vlib/v/checker/tests/cast_string_to_char_err.out
Normal file
@ -0,0 +1,5 @@
|
||||
vlib/v/checker/tests/cast_string_to_char_err.vv:2:7: error: cannot cast string to `char`, use `'a'[index]` instead.
|
||||
1 | fn main() {
|
||||
2 | _ := char('a')
|
||||
| ~~~~~~~~~
|
||||
3 | }
|
3
vlib/v/checker/tests/cast_string_to_char_err.vv
Normal file
3
vlib/v/checker/tests/cast_string_to_char_err.vv
Normal file
@ -0,0 +1,3 @@
|
||||
fn main() {
|
||||
_ := char('a')
|
||||
}
|
Loading…
Reference in New Issue
Block a user