parser: fix fmt error for json decode (#14520)

yuyi 2022-05-25 13:59:22 +08:00 committed by Jef Roosens
parent 7b0dae5da7
commit 7c46e94b25
Signed by: Jef Roosens
GPG Key ID: B75D4F293C7052DB
2 changed files with 19 additions and 1 deletions

View File

@ -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} ')?)
}

View File

@ -24,7 +24,6 @@ pub fn (mut p Parser) call_expr(language ast.Language, mod string) ast.CallExpr
mut or_kind := ast.OrKind.absent mut or_kind := ast.OrKind.absent
if fn_name == 'json.decode' { if fn_name == 'json.decode' {
p.expecting_type = true // Makes name_expr() parse the type `User` in `json.decode(User, txt)` 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 old_expr_mod := p.expr_mod