Skip to content

Commit

Permalink
parser: fix panic for struct field with new style @[attribute], with …
Browse files Browse the repository at this point in the history
…an enum default value after it
  • Loading branch information
spytheman committed Nov 21, 2023
1 parent 09ed7d7 commit e3d306d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
3 changes: 2 additions & 1 deletion vlib/v/parser/parse_type.v
Expand Up @@ -547,7 +547,8 @@ fn (mut p Parser) parse_any_type(language ast.Language, is_ptr bool, check_dot b
name = 'C.${name}'
} else if language == .js {
name = 'JS.${name}'
} else if p.peek_tok.kind == .dot && check_dot && !name[0].is_capital() {
} else if p.peek_tok.kind == .dot && check_dot && p.tok.lit.len > 0
&& !p.tok.lit[0].is_capital() {
// `module.Type`
mut mod := name
mut mod_pos := p.tok.pos()
Expand Down
@@ -0,0 +1,6 @@
vlib/v/parser/tests/expecting_type_declaration_for_new_attribute_field_followed_by_enum_default_value.vv:9:23: error: expecting type declaration
7 | s string
8 | i int
9 | e MyEnum @[required] = .a
| ^
10 | }
@@ -0,0 +1,10 @@
enum MyEnum {
a
b
}

struct MyStruct {
s string
i int
e MyEnum @[required] = .a
}

0 comments on commit e3d306d

Please sign in to comment.