Skip to content

Commit

Permalink
parser: allow struct definitions inside functions
Browse files Browse the repository at this point in the history
  • Loading branch information
medvednikov committed Oct 6, 2024
1 parent 4f9df0d commit a2d385a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 2 additions & 2 deletions doc/docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -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')
}
Expand Down Expand Up @@ -8065,4 +8065,4 @@ Assignment Operators
&= |= ^=
>>= <<= >>>=
&&= ||=
```
```
4 changes: 4 additions & 0 deletions vlib/v/parser/parser.v
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit a2d385a

Please sign in to comment.