@@ -924,6 +924,52 @@ fn (mut g Gen) resolved_ident_map_value_type(expr ast.Ident) ast.Type {
924924 return 0
925925}
926926
927+ fn (mut g Gen) resolved_map_key_value_types (map_type ast.Type, fallback_key_type ast.Type, fallback_value_type ast.Type) (ast.Type, ast.Type) {
928+ mut key_type := g.unwrap_generic (g.recheck_concrete_type (fallback_key_type))
929+ mut value_type := g.unwrap_generic (g.recheck_concrete_type (fallback_value_type))
930+ resolved_map_type := g.unwrap_generic (g.recheck_concrete_type (map_type))
931+ map_sym := g.table.final_sym (resolved_map_type)
932+ if map_sym.kind == .map {
933+ map_info := map_sym.map_info ()
934+ resolved_key := g.unwrap_generic (g.recheck_concrete_type (map_info.key_type))
935+ resolved_value := g.unwrap_generic (g.recheck_concrete_type (map_info.value_type))
936+ if resolved_key != 0 {
937+ key_type = resolved_key
938+ }
939+ if resolved_value != 0 {
940+ value_type = resolved_value
941+ }
942+ if key_type == ast.usize_type || value_type == ast.usize_type {
943+ name_key_type , name_value_type := g.resolved_map_types_from_name (map_sym.name)
944+ if key_type == ast.usize_type && name_key_type != 0 {
945+ key_type = name_key_type
946+ }
947+ if value_type == ast.usize_type && name_value_type != 0 {
948+ value_type = name_value_type
949+ }
950+ }
951+ }
952+ if key_type == 0 {
953+ key_type = fallback_key_type
954+ }
955+ if value_type == 0 {
956+ value_type = fallback_value_type
957+ }
958+ return key_type, value_type
959+ }
960+
961+ fn (mut g Gen) resolved_map_type_from_expr (expr ast.Expr, default_type ast.Type) ast.Type {
962+ mut map_type := g.recheck_concrete_type (default_type)
963+ resolved_type := g.recheck_concrete_type (g.resolved_expr_type (expr, default_type))
964+ if resolved_type != 0
965+ && (g.cur_concrete_types.len > 0 || map_type == 0 || map_type.has_flag (.generic)
966+ || g.type_has_unresolved_generic_parts (map_type)
967+ || g.unwrap_generic (resolved_type) != g.unwrap_generic (map_type)) {
968+ map_type = resolved_type
969+ }
970+ return map_type
971+ }
972+
927973fn (mut g Gen) resolved_array_elem_type_from_name (name string ) ast.Type {
928974 if ! name.starts_with ('[]' ) {
929975 return 0
0 commit comments