mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: minor cleanup in cast_expr() (#12954)
This commit is contained in:
parent
d69d2c600b
commit
a83786d867
@ -3487,10 +3487,8 @@ pub fn (mut c Checker) cast_expr(mut node ast.CastExpr) ast.Type {
|
|||||||
c.error('cannot convert type `$from_type_sym.name` to `$to_type_sym.name` (alias to `$to_type_sym_final.name`)',
|
c.error('cannot convert type `$from_type_sym.name` to `$to_type_sym.name` (alias to `$to_type_sym_final.name`)',
|
||||||
node.pos)
|
node.pos)
|
||||||
}
|
}
|
||||||
} else if to_type_sym.kind == .byte && from_type != ast.voidptr_type
|
} else if to_type_sym.kind == .byte && from_type_sym.kind == .alias
|
||||||
&& from_type_sym.kind != .enum_ && !from_type.is_int() && !from_type.is_float()
|
&& from_type_sym_final.kind != .byte && !from_type.is_ptr() {
|
||||||
&& from_type != ast.bool_type && !from_type.is_ptr() && from_type_sym.kind == .alias
|
|
||||||
&& from_type_sym_final.name != 'byte' {
|
|
||||||
type_name := c.table.type_to_str(from_type)
|
type_name := c.table.type_to_str(from_type)
|
||||||
c.error('cannot cast type `$type_name` to `byte`', node.pos)
|
c.error('cannot cast type `$type_name` to `byte`', node.pos)
|
||||||
} else if to_type_sym.kind == .struct_ && !to_type.is_ptr()
|
} else if to_type_sym.kind == .struct_ && !to_type.is_ptr()
|
||||||
|
7
vlib/v/checker/tests/cast_alias_to_byte_err.out
Normal file
7
vlib/v/checker/tests/cast_alias_to_byte_err.out
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
vlib/v/checker/tests/cast_alias_to_byte_err.vv:5:7: error: cannot cast type `Foo` to `byte`
|
||||||
|
3 | fn main() {
|
||||||
|
4 | a := Foo('hello')
|
||||||
|
5 | b := byte(a)
|
||||||
|
| ~~~~~~~
|
||||||
|
6 | println(b)
|
||||||
|
7 | }
|
7
vlib/v/checker/tests/cast_alias_to_byte_err.vv
Normal file
7
vlib/v/checker/tests/cast_alias_to_byte_err.vv
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
type Foo = string
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
a := Foo('hello')
|
||||||
|
b := byte(a)
|
||||||
|
println(b)
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user