From 3cb1bb7c36be14e33f8af419591201be8e5a4952 Mon Sep 17 00:00:00 2001 From: StunxFS <56417208+StunxFS@users.noreply.github.com> Date: Fri, 12 Mar 2021 13:02:09 -0400 Subject: [PATCH] checker: check the amount of parameters passed to `json.decode()` (#9267) --- vlib/v/checker/checker.v | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index af472ebf25..840ee489f2 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -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()