@@ -872,6 +872,12 @@ fn (t &Transformer) is_interface_var(name string) bool {
872872// get_var_type_name returns the type name of a variable from scope lookup
873873fn (t &Transformer) get_var_type_name (name string ) string {
874874 typ := t.lookup_var_type (name) or { return '' }
875+ if typ is types.Alias {
876+ if typ.name != '' {
877+ return typ.name
878+ }
879+ return t.type_to_name (typ.base_type)
880+ }
875881 if typ is types.String {
876882 return 'string'
877883 }
@@ -6180,7 +6186,11 @@ fn (mut t Transformer) transform_index_expr(expr ast.IndexExpr) ast.Expr {
61806186
61816187 // Lower map reads `m[key]` to `map__get(&m, &key, &zero)` in transformer so backends
61826188 // do not need map-specific IndexExpr logic.
6183- if map_expr_typ := t.get_expr_type (expr.lhs) {
6189+ mut map_expr_type_opt := t.get_expr_type (expr.lhs)
6190+ if map_expr_type_opt == none && expr.lhs is ast.Ident {
6191+ map_expr_type_opt = t.lookup_var_type ((expr.lhs as ast.Ident ).name)
6192+ }
6193+ if map_expr_typ := map_expr_type_opt {
61846194 if map_type := t.unwrap_map_type (map_expr_typ) {
61856195 synth_pos := t.next_synth_pos ()
61866196
@@ -9543,8 +9553,8 @@ fn (t &Transformer) infer_variant_type(value ast.Expr, variants []string) string
95439553 }
95449554 }
95459555 // Prefer checker-provided types for match/smartcast narrowing.
9546- if value.pos > 0 {
9547- if typ := t.env.get_expr_type (value.pos) {
9556+ if value.pos. is_valid () {
9557+ if typ := t.env.get_expr_type (value.pos.id ) {
95489558 matched2 := match_sumtype_variant_name (t.type_to_c_name (typ), variants)
95499559 if matched2 != '' {
95509560 return matched2
@@ -10873,15 +10883,16 @@ fn (mut t Transformer) empty_struct_arg_expr(param_type types.Type) ast.Expr {
1087310883 if t.is_pointer_type (param_type) {
1087410884 mut cur := param_type
1087510885 for cur is types.Alias {
10876- cur = cur.base_type
10886+ cur = cur.base_type ()
1087710887 }
1087810888 if cur is types.Pointer {
10889+ ptr := cur as types.Pointer
1087910890 init_pos := t.next_synth_pos ()
1088010891 ptr_pos := t.next_synth_pos ()
10881- t.register_synth_type (init_pos, cur .base_type)
10892+ t.register_synth_type (init_pos, ptr .base_type)
1088210893 t.register_synth_type (ptr_pos, param_type)
1088310894 init_expr := ast.Expr (ast.InitExpr{
10884- typ: t.type_to_ast_type_expr (cur .base_type)
10895+ typ: t.type_to_ast_type_expr (ptr .base_type)
1088510896 pos: init_pos
1088610897 })
1088710898 return ast.Expr (ast.PrefixExpr{
@@ -11036,10 +11047,11 @@ fn (mut t Transformer) lower_struct_shorthand_call(args []ast.Expr, param_types
1103611047 if t.is_pointer_type (param_type) {
1103711048 mut cur := param_type
1103811049 for cur is types.Alias {
11039- cur = cur.base_type
11050+ cur = cur.base_type ()
1104011051 }
1104111052 if cur is types.Pointer {
11042- init_typ = cur.base_type
11053+ ptr := cur as types.Pointer
11054+ init_typ = ptr.base_type
1104311055 }
1104411056 }
1104511057 init_pos := t.next_synth_pos ()
0 commit comments