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

parser: fix anon struct name conflict (#15517)

This commit is contained in:
shove 2022-08-26 12:01:50 +08:00 committed by GitHub
parent 3eb6ad7b8c
commit c10c8ff9e4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 8 additions and 3 deletions

View File

@ -47,6 +47,8 @@ pub mut:
// cache for type_to_str_using_aliases
cached_type_to_str map[u64]string
anon_struct_names map[string]int // anon struct name -> struct sym idx
// counter for anon struct, avoid name conflicts.
anon_struct_counter int
}
// used by vls to avoid leaks

View File

@ -91,7 +91,6 @@ mut:
if_cond_comments []ast.Comment
script_mode bool
script_mode_start_token token.Token
anon_struct_counter int
pub mut:
scanner &scanner.Scanner
errors []errors.Error

View File

@ -41,8 +41,8 @@ fn (mut p Parser) struct_decl(is_anon bool) ast.StructDecl {
return ast.StructDecl{}
}
mut name := if is_anon {
p.anon_struct_counter++
'_VAnonStruct$p.anon_struct_counter'
p.table.anon_struct_counter++
'_VAnonStruct$p.table.anon_struct_counter'
} else {
p.check_name()
}

View File

@ -261,3 +261,7 @@ fn test_fn_is_html_open_tag() {
b = is_html_open_tag('style', s)
assert b == false
}
// For issue #15516
fn test_anon_struct() {
}