checker: check using a map as a struct init in parameter (#10904)

pull/10890/head
Louis Schmieder 2021-07-22 09:42:59 +02:00 committed by GitHub
parent d7dcb47db3
commit 742f6f849c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 0 deletions

View File

@ -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)