1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

checker: fix index type check

This commit is contained in:
Alexander Medvednikov 2020-03-31 17:51:16 +02:00
parent f98cc9c017
commit 43f72246aa

View File

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