From 7c46e94b252d1e6d05f1ee9d12e547e98ff2012b Mon Sep 17 00:00:00 2001 From: yuyi Date: Wed, 25 May 2022 13:59:22 +0800 Subject: [PATCH] parser: fix fmt error for json decode (#14520) --- vlib/v/fmt/tests/json_decode_fmt_keep.vv | 19 +++++++++++++++++++ vlib/v/parser/fn.v | 1 - 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 vlib/v/fmt/tests/json_decode_fmt_keep.vv diff --git a/vlib/v/fmt/tests/json_decode_fmt_keep.vv b/vlib/v/fmt/tests/json_decode_fmt_keep.vv new file mode 100644 index 0000000000..d560638158 --- /dev/null +++ b/vlib/v/fmt/tests/json_decode_fmt_keep.vv @@ -0,0 +1,19 @@ +import json + +struct Request { + a int +} + +fn parse(s string) ?Request { + return json.decode(Request, s) +} + +fn parse2(s string) ?Request { + req := json.decode(Request, s)? + return req +} + +fn main() { + println(parse('{"a": 22} ')?) + println(parse2('{"a": 22} ')?) +} diff --git a/vlib/v/parser/fn.v b/vlib/v/parser/fn.v index 10a6e84206..8bf0b45039 100644 --- a/vlib/v/parser/fn.v +++ b/vlib/v/parser/fn.v @@ -24,7 +24,6 @@ pub fn (mut p Parser) call_expr(language ast.Language, mod string) ast.CallExpr mut or_kind := ast.OrKind.absent if fn_name == 'json.decode' { p.expecting_type = true // Makes name_expr() parse the type `User` in `json.decode(User, txt)` - or_kind = .block } old_expr_mod := p.expr_mod