checker: minor cleanup in cast_expr() (#12954)
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`)',
|
||||
node.pos)
|
||||
}
|
||||
} else if to_type_sym.kind == .byte && from_type != ast.voidptr_type
|
||||
&& from_type_sym.kind != .enum_ && !from_type.is_int() && !from_type.is_float()
|
||||
&& from_type != ast.bool_type && !from_type.is_ptr() && from_type_sym.kind == .alias
|
||||
&& from_type_sym_final.name != 'byte' {
|
||||
} else if to_type_sym.kind == .byte && from_type_sym.kind == .alias
|
||||
&& from_type_sym_final.kind != .byte && !from_type.is_ptr() {
|
||||
type_name := c.table.type_to_str(from_type)
|
||||
c.error('cannot cast type `$type_name` to `byte`', node.pos)
|
||||
} else if to_type_sym.kind == .struct_ && !to_type.is_ptr()
|
||||
|
|
|
@ -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 | }
|
|
@ -0,0 +1,7 @@
|
|||
type Foo = string
|
||||
|
||||
fn main() {
|
||||
a := Foo('hello')
|
||||
b := byte(a)
|
||||
println(b)
|
||||
}
|
Loading…
Reference in New Issue