checker: check the amount of parameters passed to `json.decode()` (#9267)

pull/9275/head
StunxFS 2021-03-12 13:02:09 -04:00 committed by GitHub
parent 90d942e2ec
commit 3cb1bb7c36
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 0 deletions

View File

@ -1728,6 +1728,11 @@ pub fn (mut c Checker) call_fn(mut call_expr ast.CallExpr) table.Type {
}
if fn_name == 'json.encode' {
} else if fn_name == 'json.decode' && call_expr.args.len > 0 {
if call_expr.args.len != 2 {
c.error("json.decode expects 2 arguments, a type and a string (e.g `json.decode(T, '')`)",
call_expr.pos)
return table.void_type
}
expr := call_expr.args[0].expr
if expr !is ast.Type {
typ := expr.type_name()