checker: ensure array init matches the array's type (#7118)

pull/7137/head
spaceface777 2020-12-04 19:39:32 +01:00 committed by GitHub
parent 215a76a715
commit 6a47deb3f8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 1 deletions

View File

@ -2317,7 +2317,10 @@ pub fn (mut c Checker) array_init(mut array_init ast.ArrayInit) table.Type {
}
sym := c.table.get_type_symbol(array_init.elem_type)
if array_init.has_default {
c.expr(array_init.default_expr)
default_typ := c.expr(array_init.default_expr)
c.check_expected(default_typ, array_init.elem_type) or {
c.error(err, array_init.default_expr.position())
}
}
if sym.kind == .sum_type {
if array_init.has_len && !array_init.has_default {