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

checker: type x does not support indexing

This commit is contained in:
Alexander Medvednikov 2020-06-19 12:53:53 +02:00
parent 5f5228f0f3
commit e8b21b4242

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)