checker: allow casting strings to string aliases
parent
ce6f687f65
commit
a8b0dfb38a
|
@ -703,7 +703,7 @@ pub struct CastExpr {
|
|||
pub:
|
||||
expr Expr // `buf`
|
||||
arg Expr // `n` in `string(buf, n)`
|
||||
typ table.Type // `string`
|
||||
typ table.Type // `string` TODO rename to `type_to_cast_to`
|
||||
pos token.Position
|
||||
pub mut:
|
||||
typname string
|
||||
|
|
|
@ -1962,6 +1962,8 @@ pub fn (mut c Checker) expr(node ast.Expr) table.Type {
|
|||
node.pos)
|
||||
}
|
||||
if node.expr_type == table.string_type {
|
||||
cast_to_type_sym := c.table.get_type_symbol(node.typ)
|
||||
if cast_to_type_sym.kind != .alias {
|
||||
mut error_msg := 'cannot cast a string'
|
||||
if node.expr is ast.StringLiteral {
|
||||
str_lit := node.expr as ast.StringLiteral
|
||||
|
@ -1971,6 +1973,7 @@ pub fn (mut c Checker) expr(node ast.Expr) table.Type {
|
|||
}
|
||||
c.error(error_msg, node.pos)
|
||||
}
|
||||
}
|
||||
if node.has_arg {
|
||||
c.expr(node.arg)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue