mirror of
https://github.com/vlang/v.git
synced 2025-09-14 23:12:33 +03:00
do not allow casting a type to itself
This commit is contained in:
parent
a854d396ff
commit
d7ccbba2c9
5 changed files with 17 additions and 12 deletions
|
@ -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('*')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue