mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
compiler: add error when embedding struct in itself
This commit is contained in:
parent
a5b4ed2909
commit
5fb3c0e3a8
@ -722,6 +722,7 @@ fn (p mut Parser) struct_decl() {
|
|||||||
// p.next()
|
// p.next()
|
||||||
// }
|
// }
|
||||||
// Check if reserved name
|
// Check if reserved name
|
||||||
|
field_name_token_idx := p.cur_tok_index()
|
||||||
field_name := if name != 'Option' { p.table.var_cgen_name(p.check_name()) } else { p.check_name() }
|
field_name := if name != 'Option' { p.table.var_cgen_name(p.check_name()) } else { p.check_name() }
|
||||||
// Check dups
|
// Check dups
|
||||||
if field_name in names {
|
if field_name in names {
|
||||||
@ -744,6 +745,9 @@ fn (p mut Parser) struct_decl() {
|
|||||||
access_mod := if is_pub{AccessMod.public} else { AccessMod.private}
|
access_mod := if is_pub{AccessMod.public} else { AccessMod.private}
|
||||||
p.fgen(' ')
|
p.fgen(' ')
|
||||||
field_type := p.get_type()
|
field_type := p.get_type()
|
||||||
|
if field_type == name {
|
||||||
|
p.error_with_token_index( 'cannot embed struct `$name` in itself (field `$field_name`)', field_name_token_idx)
|
||||||
|
}
|
||||||
p.check_and_register_used_imported_type(field_type)
|
p.check_and_register_used_imported_type(field_type)
|
||||||
is_atomic := p.tok == .key_atomic
|
is_atomic := p.tok == .key_atomic
|
||||||
if is_atomic {
|
if is_atomic {
|
||||||
|
Loading…
Reference in New Issue
Block a user