From a2d385aee3f1295966991ab9caf1d98319de479d Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Sun, 6 Oct 2024 22:37:29 +0300 Subject: [PATCH] parser: allow struct definitions inside functions --- doc/docs.md | 4 ++-- vlib/v/parser/parser.v | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/doc/docs.md b/doc/docs.md index f196f212c07688..c113bc7ca7b238 100644 --- a/doc/docs.md +++ b/doc/docs.md @@ -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 &= |= ^= >>= <<= >>>= &&= ||= -``` \ No newline at end of file +``` diff --git a/vlib/v/parser/parser.v b/vlib/v/parser/parser.v index 6f28c341574415..d0e2287c8b583f 100644 --- a/vlib/v/parser/parser.v +++ b/vlib/v/parser/parser.v @@ -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)