From 742f6f849ced77ba4796fb8a9f597135fa78546a Mon Sep 17 00:00:00 2001 From: Louis Schmieder Date: Thu, 22 Jul 2021 09:42:59 +0200 Subject: [PATCH] checker: check using a map as a struct init in parameter (#10904) --- vlib/v/checker/checker.v | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index e85a6cdc99..56a090e75a 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -2801,6 +2801,16 @@ pub fn (mut c Checker) fn_call(mut call_expr ast.CallExpr) ast.Type { } } c.expected_type = param.typ + + e_sym := c.table.get_type_symbol(c.expected_type) + if call_arg.expr is ast.MapInit && e_sym.kind == .struct_ { + c.error('cannot initialize a struct with a map', call_arg.pos) + continue + } else if call_arg.expr is ast.StructInit && e_sym.kind == .map { + c.error('cannot initialize a map with a struct', call_arg.pos) + continue + } + typ := c.check_expr_opt_call(call_arg.expr, c.expr(call_arg.expr)) call_expr.args[i].typ = typ typ_sym := c.table.get_type_symbol(typ)