Skip to content

Commit 475836b

Browse files
authored
parser: fix invalid field name checking (fix #24279) (#24283)
1 parent a0a8324 commit 475836b

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

vlib/v/parser/struct.v

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,11 @@ fn (mut p Parser) struct_decl(is_anon bool) ast.StructDecl {
218218
}
219219

220220
if is_embed {
221+
if p.peek_tok.kind == .dot && p.peek_tok.line_nr == p.peek_token(3).line_nr
222+
&& p.peek_token(3).kind == .name {
223+
p.error_with_pos('invalid field name', p.tok.pos())
224+
return ast.StructDecl{}
225+
}
221226
// struct embedding
222227
type_pos = p.tok.pos()
223228
typ = p.parse_type()
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
vlib/v/parser/tests/invalid_field_name_err.vv:2:2: error: invalid field name
2+
1 | struct MyStruct {
3+
2 | c.close int
4+
| ^
5+
3 | }
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
struct MyStruct {
2+
c.close int
3+
}

0 commit comments

Comments
 (0)