From 43f72246aa45ec5e6b2079ec9abe51e8ce0d58fe Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Tue, 31 Mar 2020 17:51:16 +0200 Subject: [PATCH] checker: fix index type check --- vlib/v/checker/checker.v | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index 5aee65b558..374ee21241 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -1019,8 +1019,9 @@ pub fn (c mut Checker) index_expr(node mut ast.IndexExpr) table.Type { index_type := c.expr(node.index) index_type_sym := c.table.get_type_symbol(index_type) // println('index expr left=$typ_sym.name $node.pos.line_nr') - // if typ_sym.kind == .array && (!(table.type_idx(index_type) in table.number_type_idxs) && index_type_sym.kind != .enum_) { - if typ_sym.kind in [.array, .array_fixed] && !(table.is_number(index_type) && index_type_sym.kind != .enum_) { + // if typ_sym.kind == .array && (!(table.type_idx(index_type) in table.number_type_idxs) && + // index_type_sym.kind != .enum_) { + if typ_sym.kind in [.array, .array_fixed] && !(table.is_number(index_type) || index_type_sym.kind == .enum_) { c.error('non-integer index `$index_type_sym.name` (array type `$typ_sym.name`)', node.pos) } else if typ_sym.kind == .map && table.type_idx(index_type) != table.string_type_idx {