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

do not allow casting a type to itself

This commit is contained in:
Alexander Medvednikov
2019-12-07 15:31:56 +03:00
parent a854d396ff
commit d7ccbba2c9
5 changed files with 17 additions and 12 deletions

View File

@ -527,6 +527,10 @@ fn (p mut Parser) cast(typ string) {
p.check(.lpar)
p.expected_type = typ
expr_typ := p.bool_expression()
// Do not allow `int(my_int)`
if expr_typ == typ {
p.warn('casting `$typ` to `$expr_typ` is not needed')
}
// `face := FT_Face(cobj)` => `FT_Face face = *((FT_Face*)cobj);`
casting_voidptr_to_value := expr_typ == 'void*' && typ != 'int' &&
typ != 'byteptr' && !typ.ends_with('*')