checker: allow casting from floats/enums to byte

pull/6560/head
Delyan Angelov 2020-10-04 14:46:24 +03:00
parent aa81ebb600
commit 628b136e85
1 changed files with 3 additions and 2 deletions

View File

@ -2627,8 +2627,9 @@ pub fn (mut c Checker) expr(node ast.Expr) table.Type {
}
c.error(error_msg, node.pos)
}
} else if !node.expr_type.is_int() && node.expr_type != table.voidptr_type && !node.expr_type.is_ptr() &&
to_type_sym.kind == .byte {
} else if to_type_sym.kind == .byte &&
node.expr_type != table.voidptr_type && from_type_sym.kind != .enum_ && !node.expr_type.is_int() &&
!node.expr_type.is_float() && !node.expr_type.is_ptr() {
type_name := c.table.type_to_str(node.expr_type)
c.error('cannot cast type `$type_name` to `byte`', node.pos)
} else if to_type_sym.kind == .struct_ && !node.typ.is_ptr() && !(to_type_sym.info as table.Struct).is_typedef {