diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index 476d6f67eb..2bcb652599 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -4643,7 +4643,7 @@ fn (mut c Checker) check_index_type(typ_sym &table.TypeSymbol, index_type table. pub fn (mut c Checker) index_expr(mut node ast.IndexExpr) table.Type { typ := c.expr(node.left) node.left_type = typ - typ_sym := c.table.get_type_symbol(typ) + typ_sym := c.table.get_final_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) diff --git a/vlib/v/gen/cgen.v b/vlib/v/gen/cgen.v index 86ee4aea52..f14c799a6c 100644 --- a/vlib/v/gen/cgen.v +++ b/vlib/v/gen/cgen.v @@ -3846,7 +3846,7 @@ fn (mut g Gen) index_expr(node ast.IndexExpr) { g.write(')') } else { - sym := g.table.get_type_symbol(node.left_type) + sym := g.table.get_final_type_symbol(node.left_type) left_is_ptr := node.left_type.is_ptr() if sym.kind == .array { info := sym.info as table.Array diff --git a/vlib/v/table/table.v b/vlib/v/table/table.v index 10164861fc..0938f5c93c 100644 --- a/vlib/v/table/table.v +++ b/vlib/v/table/table.v @@ -638,7 +638,7 @@ pub fn (mut t Table) add_placeholder_type(name string, language Language) int { [inline] pub fn (t &Table) value_type(typ Type) Type { - typ_sym := t.get_type_symbol(typ) + typ_sym := t.get_final_type_symbol(typ) if typ.has_flag(.variadic) { // ...string => string // return typ.clear_flag(.variadic) diff --git a/vlib/v/tests/array_type_alias_test.v b/vlib/v/tests/array_type_alias_test.v new file mode 100644 index 0000000000..17ee8d62ec --- /dev/null +++ b/vlib/v/tests/array_type_alias_test.v @@ -0,0 +1,6 @@ +type Test = []int + +fn test_index() { + t := Test([2,4]) + assert t[1] == 4 +} diff --git a/vlib/v/tests/map_type_alias_test.v b/vlib/v/tests/map_type_alias_test.v new file mode 100644 index 0000000000..3c6d63b076 --- /dev/null +++ b/vlib/v/tests/map_type_alias_test.v @@ -0,0 +1,6 @@ +type Test = map[string]string + +fn test_index() { + t := Test({'c': 'abc'}) + assert t['c'] == 'abc' +}