1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

as casting

This commit is contained in:
Alexander Medvednikov
2019-12-30 10:45:56 +01:00
parent 2d597d7804
commit cba6a6fdea
3 changed files with 18 additions and 2 deletions

View File

@ -60,6 +60,18 @@ fn (p mut Parser) bool_expression() string {
p.gen('}, sizeof($typ) ), .typ = SumType_${tt} }')//${val}_type }')
}
}
// `as` cast
// TODO remove copypasta
if p.tok == .key_as {
p.next()
cast_typ := p.get_type()
if typ == cast_typ {
p.warn('casting `$typ` to `$cast_typ` is not needed')
}
p.cgen.set_placeholder(start_ph, '($cast_typ)(')
p.gen(')')
return cast_typ
}
return typ
}