mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
parent
216a505c2a
commit
7fd08eca96
@ -2732,6 +2732,11 @@ pub fn (mut c Checker) cast_expr(mut node ast.CastExpr) ast.Type {
|
||||
node.pos)
|
||||
}
|
||||
|
||||
if to_sym.kind == .rune && from_sym.is_string() {
|
||||
snexpr := node.expr.str()
|
||||
c.error('cannot cast `$from_sym.name` to rune, use `${snexpr}.runes()` instead.', node.pos)
|
||||
}
|
||||
|
||||
if to_type == ast.string_type {
|
||||
if from_type in [ast.byte_type, ast.bool_type] {
|
||||
snexpr := node.expr.str()
|
||||
|
26
vlib/v/checker/tests/cast_string_to_rune_err.out
Normal file
26
vlib/v/checker/tests/cast_string_to_rune_err.out
Normal file
@ -0,0 +1,26 @@
|
||||
vlib/v/checker/tests/cast_string_to_rune_err.vv:2:7: error: cannot cast `string` to rune, use `'0'.runes()` instead.
|
||||
1 | fn main() {
|
||||
2 | _ := rune('0')
|
||||
| ~~~~~~~~~
|
||||
3 | _ := rune('012345')
|
||||
4 | _ := rune('v')
|
||||
vlib/v/checker/tests/cast_string_to_rune_err.vv:3:7: error: cannot cast `string` to rune, use `'012345'.runes()` instead.
|
||||
1 | fn main() {
|
||||
2 | _ := rune('0')
|
||||
3 | _ := rune('012345')
|
||||
| ~~~~~~~~~~~~~~
|
||||
4 | _ := rune('v')
|
||||
5 | _ := rune('abcd')
|
||||
vlib/v/checker/tests/cast_string_to_rune_err.vv:4:7: error: cannot cast `string` to rune, use `'v'.runes()` instead.
|
||||
2 | _ := rune('0')
|
||||
3 | _ := rune('012345')
|
||||
4 | _ := rune('v')
|
||||
| ~~~~~~~~~
|
||||
5 | _ := rune('abcd')
|
||||
6 | }
|
||||
vlib/v/checker/tests/cast_string_to_rune_err.vv:5:7: error: cannot cast `string` to rune, use `'abcd'.runes()` instead.
|
||||
3 | _ := rune('012345')
|
||||
4 | _ := rune('v')
|
||||
5 | _ := rune('abcd')
|
||||
| ~~~~~~~~~~~~
|
||||
6 | }
|
6
vlib/v/checker/tests/cast_string_to_rune_err.vv
Normal file
6
vlib/v/checker/tests/cast_string_to_rune_err.vv
Normal file
@ -0,0 +1,6 @@
|
||||
fn main() {
|
||||
_ := rune('0')
|
||||
_ := rune('012345')
|
||||
_ := rune('v')
|
||||
_ := rune('abcd')
|
||||
}
|
Loading…
Reference in New Issue
Block a user