v2: checker - save type in MapInit node

pull/3903/head
joe-conigliaro 2020-03-02 14:24:45 +11:00
parent b333d02e3b
commit a118c72423
1 changed files with 5 additions and 3 deletions

View File

@ -513,7 +513,7 @@ pub fn (c mut Checker) expr(node ast.Expr) table.Type {
return table.int_type return table.int_type
} }
ast.MapInit { ast.MapInit {
return c.map_init(it) return c.map_init(mut it)
} }
ast.MatchExpr { ast.MatchExpr {
return c.match_expr(mut it) return c.match_expr(mut it)
@ -803,7 +803,7 @@ pub fn (c mut Checker) enum_val(node ast.EnumVal) table.Type {
return typ_idx return typ_idx
} }
pub fn (c mut Checker) map_init(node ast.MapInit) table.Type { pub fn (c mut Checker) map_init(node mut ast.MapInit) table.Type {
key0_type := c.expr(node.keys[0]) key0_type := c.expr(node.keys[0])
val0_type := c.expr(node.vals[0]) val0_type := c.expr(node.vals[0])
for i, key in node.keys { for i, key in node.keys {
@ -824,7 +824,9 @@ pub fn (c mut Checker) map_init(node ast.MapInit) table.Type {
c.error('map init: cannot use `$val_type_sym.name` as `$val0_type_sym` for map value', node.pos) c.error('map init: cannot use `$val_type_sym.name` as `$val0_type_sym` for map value', node.pos)
} }
} }
return table.new_type(c.table.find_or_register_map(key0_type, val0_type)) map_type := table.new_type(c.table.find_or_register_map(key0_type, val0_type))
node.typ = map_type
return map_type
} }
// TODO: remove once all exprs/stmts are handled // TODO: remove once all exprs/stmts are handled