v2: start to fix index expr for map/array/fixed array
							parent
							
								
									42399d24d9
								
							
						
					
					
						commit
						69634c60b3
					
				|  | @ -544,31 +544,30 @@ pub fn (c mut Checker) index_expr(node ast.IndexExpr) table.Type { | |||
| 		} | ||||
| 		else {} | ||||
| 	} | ||||
| 	index_type := c.expr(node.index) | ||||
| 	// if index_type.typ.kind != .int {
 | ||||
| 	if table.type_idx(index_type) != table.int_type_idx { | ||||
| 		index_type_sym := c.table.get_type_symbol(index_type) | ||||
| 		c.error('non-integer index (type `$index_type_sym.name`)', node.pos) | ||||
| 	} | ||||
| 	typ_sym := c.table.get_type_symbol(typ) | ||||
| 	if typ_sym.kind == .array { | ||||
| 		if is_range {} // `x[start..end]` has the same type as `x`
 | ||||
| 		else { | ||||
| 	if !is_range { | ||||
| 		index_type := c.expr(node.index) | ||||
| 		// if index_type.typ.kind != .int {
 | ||||
| 		if table.type_idx(index_type) != table.int_type_idx { | ||||
| 			index_type_sym := c.table.get_type_symbol(index_type) | ||||
| 			c.error('non-integer index (type `$index_type_sym.name`)', node.pos) | ||||
| 		} | ||||
| 		if typ_sym.kind == .array { | ||||
| 			// Check index type
 | ||||
| 			info := typ_sym.info as table.Array | ||||
| 			return info.elem_type | ||||
| 		} | ||||
| 	} | ||||
| 	if typ_sym.kind == .array_fixed { | ||||
| 		info := typ_sym.info as table.ArrayFixed | ||||
| 		return info.elem_type | ||||
| 	} | ||||
| 	else if typ_sym.kind == .map { | ||||
| 		info := typ_sym.info as table.Map | ||||
| 		return info.value_type | ||||
| 	} | ||||
| 	else { | ||||
| 		typ = table.int_type | ||||
| 		if typ_sym.kind == .array_fixed { | ||||
| 			info := typ_sym.info as table.ArrayFixed | ||||
| 			return info.elem_type | ||||
| 		} | ||||
| 		else if typ_sym.kind == .map { | ||||
| 			info := typ_sym.info as table.Map | ||||
| 			return info.value_type | ||||
| 		} | ||||
| 		else { | ||||
| 			typ = table.int_type | ||||
| 		} | ||||
| 	} | ||||
| 	return typ | ||||
| } | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue