checker: type `x` does not support indexing

pull/5423/head
Alexander Medvednikov 2020-06-19 12:53:53 +02:00
parent 5f5228f0f3
commit e8b21b4242
1 changed files with 4 additions and 0 deletions

View File

@ -2428,6 +2428,10 @@ pub fn (mut c Checker) index_expr(mut node ast.IndexExpr) table.Type {
else {}
}
typ_sym := c.table.get_type_symbol(typ)
if typ_sym.kind !in [.array, .array_fixed, .string, .map] && !typ.is_ptr() && !(!typ_sym.name[0].is_capital() &&
typ_sym.name.ends_with('ptr')) && !typ.has_flag(.variadic) { // byteptr, charptr etc
c.error('type `$typ_sym.name` does not support indexing', node.pos)
}
if !is_range {
index_type := c.expr(node.index)
index_type_sym := c.table.get_type_symbol(index_type)