Skip to content

Commit c10c8ff

Browse files
authored
parser: fix anon struct name conflict (#15517)
1 parent 3eb6ad7 commit c10c8ff

File tree

4 files changed

+8
-3
lines changed

4 files changed

+8
-3
lines changed

vlib/v/ast/table.v

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ pub mut:
4747
// cache for type_to_str_using_aliases
4848
cached_type_to_str map[u64]string
4949
anon_struct_names map[string]int // anon struct name -> struct sym idx
50+
// counter for anon struct, avoid name conflicts.
51+
anon_struct_counter int
5052
}
5153

5254
// used by vls to avoid leaks

vlib/v/parser/parser.v

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ mut:
9191
if_cond_comments []ast.Comment
9292
script_mode bool
9393
script_mode_start_token token.Token
94-
anon_struct_counter int
9594
pub mut:
9695
scanner &scanner.Scanner
9796
errors []errors.Error

vlib/v/parser/struct.v

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ fn (mut p Parser) struct_decl(is_anon bool) ast.StructDecl {
4141
return ast.StructDecl{}
4242
}
4343
mut name := if is_anon {
44-
p.anon_struct_counter++
45-
'_VAnonStruct$p.anon_struct_counter'
44+
p.table.anon_struct_counter++
45+
'_VAnonStruct$p.table.anon_struct_counter'
4646
} else {
4747
p.check_name()
4848
}

vlib/v/parser/v_parser_test.v

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,3 +261,7 @@ fn test_fn_is_html_open_tag() {
261261
b = is_html_open_tag('style', s)
262262
assert b == false
263263
}
264+
265+
// For issue #15516
266+
fn test_anon_struct() {
267+
}

0 commit comments

Comments
 (0)