checker: allow indexing through alias to int (#14177)

playX 2022-04-26 09:15:35 +00:00 committed by Jef Roosens
parent cab53d0e75
commit 0302cd69bd
Signed by: Jef Roosens
GPG Key ID: B75D4F293C7052DB
1 changed files with 3 additions and 1 deletions

View File

@ -3775,7 +3775,9 @@ fn (mut c Checker) check_index(typ_sym &ast.TypeSymbol, index ast.Expr, index_ty
// if typ_sym.kind == .array && (!(ast.type_idx(index_type) in ast.number_type_idxs) && // if typ_sym.kind == .array && (!(ast.type_idx(index_type) in ast.number_type_idxs) &&
// index_type_sym.kind != .enum_) { // index_type_sym.kind != .enum_) {
if typ_sym.kind in [.array, .array_fixed, .string] { if typ_sym.kind in [.array, .array_fixed, .string] {
if !(index_type.is_int() || index_type_sym.kind == .enum_) { if !(index_type.is_int() || index_type_sym.kind == .enum_
|| (index_type_sym.kind == .alias
&& (index_type_sym.info as ast.Alias).parent_type.is_int())) {
type_str := if typ_sym.kind == .string { type_str := if typ_sym.kind == .string {
'non-integer string index `$index_type_sym.name`' 'non-integer string index `$index_type_sym.name`'
} else { } else {