mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
gen: impl as cast
This commit is contained in:
parent
5fb90e12b1
commit
96af21ff68
@ -433,8 +433,10 @@ mut:
|
||||
|
||||
pub struct AsCast {
|
||||
pub:
|
||||
expr Expr
|
||||
typ table.Type
|
||||
expr Expr
|
||||
typ table.Type
|
||||
mut:
|
||||
expr_type table.Type
|
||||
}
|
||||
|
||||
// e.g. `[unsafe_fn]`
|
||||
|
@ -567,8 +567,7 @@ fn (c mut Checker) stmt(node ast.Stmt) {
|
||||
sym.map_info().key_type
|
||||
}
|
||||
else {
|
||||
table.int_type
|
||||
}
|
||||
table.int_type}
|
||||
}
|
||||
scope.override_var(ast.Var{
|
||||
name: it.key_var
|
||||
@ -618,6 +617,7 @@ pub fn (c mut Checker) expr(node ast.Expr) table.Type {
|
||||
return c.array_init(mut it)
|
||||
}
|
||||
ast.AsCast {
|
||||
it.expr_type = c.expr(it.expr)
|
||||
return it.typ
|
||||
}
|
||||
ast.AssignExpr {
|
||||
|
@ -562,7 +562,17 @@ fn (g mut Gen) expr(node ast.Expr) {
|
||||
else {}
|
||||
}
|
||||
ast.AsCast {
|
||||
g.write('/* as */')
|
||||
styp := g.typ(it.typ)
|
||||
expr_type_sym := g.table.get_type_symbol(it.expr_type)
|
||||
if expr_type_sym.kind == .sum_type {
|
||||
g.write('/* as */ *($styp*)')
|
||||
g.expr(it.expr)
|
||||
g.write('.obj')
|
||||
}
|
||||
else {
|
||||
g.write('/* as */ ($styp)')
|
||||
g.expr(it.expr)
|
||||
}
|
||||
}
|
||||
ast.AssignExpr {
|
||||
if ast.expr_is_blank_ident(it.left) {
|
||||
|
Loading…
Reference in New Issue
Block a user