From 42399d24d956976bb90fab096e8c77e4a2396059 Mon Sep 17 00:00:00 2001 From: joe-conigliaro Date: Wed, 19 Feb 2020 21:39:30 +1100 Subject: [PATCH] v2: fix index expr for fixed array & map --- vlib/v/checker/checker.v | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index 37282cbcd4..215d256364 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -544,21 +544,29 @@ pub fn (c mut Checker) index_expr(node ast.IndexExpr) table.Type { } else {} } + index_type := c.expr(node.index) + // if index_type.typ.kind != .int { + if table.type_idx(index_type) != table.int_type_idx { + index_type_sym := c.table.get_type_symbol(index_type) + c.error('non-integer index (type `$index_type_sym.name`)', node.pos) + } typ_sym := c.table.get_type_symbol(typ) if typ_sym.kind == .array { if is_range {} // `x[start..end]` has the same type as `x` else { // Check index type - index_type := c.expr(node.index) - // if index_type.typ.kind != .int { - if table.type_idx(index_type) != table.int_type_idx { - index_type_sym := c.table.get_type_symbol(index_type) - c.error('non-integer index (type `$index_type_sym.name`)', node.pos) - } info := typ_sym.info as table.Array return info.elem_type } } + if typ_sym.kind == .array_fixed { + info := typ_sym.info as table.ArrayFixed + return info.elem_type + } + else if typ_sym.kind == .map { + info := typ_sym.info as table.Map + return info.value_type + } else { typ = table.int_type }