parser: allow struct definitions inside functions

This commit is contained in:
Alexander Medvednikov 2024-10-06 22:37:29 +03:00
parent 4f9df0da72
commit a2d385aee3
2 changed files with 6 additions and 2 deletions

View file

@ -4067,7 +4067,7 @@ Only one `Option` or `Result` is allowed to be returned from a function. It is
possible to return multiple values and still signal an error.
```v
fn multireturn(v int) !(int, int) {
fn multi_return(v int) !(int, int) {
if v < 0 {
return error('must be positive')
}
@ -8065,4 +8065,4 @@ Assignment Operators
&= |= ^=
>>= <<= >>>=
&&= ||=
```
```

View file

@ -1157,6 +1157,10 @@ fn (mut p Parser) stmt(is_top_level bool) ast.Stmt {
.semicolon {
return p.semicolon_stmt()
}
// Allow struct definitions inside functions
.key_struct, .key_union {
return p.struct_decl(false)
}
// literals, 'if', etc. in here
else {
return p.parse_multi_expr(is_top_level)