File tree Expand file tree Collapse file tree 3 files changed +16
-4
lines changed Expand file tree Collapse file tree 3 files changed +16
-4
lines changed Original file line number Diff line number Diff line change @@ -3487,10 +3487,8 @@ pub fn (mut c Checker) cast_expr(mut node ast.CastExpr) ast.Type {
3487
3487
c.error ('cannot convert type `$from_type_sym.name ` to `$to_type_sym.name ` (alias to `$to_type_sym_final.name `)' ,
3488
3488
node.pos)
3489
3489
}
3490
- } else if to_type_sym.kind == .byte && from_type != ast.voidptr_type
3491
- && from_type_sym.kind != .enum_ && ! from_type.is_int () && ! from_type.is_float ()
3492
- && from_type != ast.bool_type && ! from_type.is_ptr () && from_type_sym.kind == .alias
3493
- && from_type_sym_final.name != 'byte' {
3490
+ } else if to_type_sym.kind == .byte && from_type_sym.kind == .alias
3491
+ && from_type_sym_final.kind != .byte && ! from_type.is_ptr () {
3494
3492
type_name := c.table.type_to_str (from_type)
3495
3493
c.error ('cannot cast type `$type_name ` to `byte`' , node.pos)
3496
3494
} else if to_type_sym.kind == .struct_ && ! to_type.is_ptr ()
Original file line number Diff line number Diff line change
1
+ vlib/v/checker/tests/cast_alias_to_byte_err.vv:5:7: error: cannot cast type `Foo` to `byte`
2
+ 3 | fn main() {
3
+ 4 | a := Foo('hello')
4
+ 5 | b := byte(a)
5
+ | ~~~~~~~
6
+ 6 | println(b)
7
+ 7 | }
Original file line number Diff line number Diff line change
1
+ type Foo = string
2
+
3
+ fn main() {
4
+ a := Foo('hello')
5
+ b := byte(a)
6
+ println(b)
7
+ }
You can’t perform that action at this time.
0 commit comments