@@ -1132,17 +1132,51 @@ fn (mut g Gen) assign_stmt(node_ ast.AssignStmt) {
11321132fn (mut g Gen) gen_multi_return_assign (node & ast.AssignStmt, return_type ast.Type, return_sym ast.TypeSymbol) {
11331133 // multi return
11341134 // TODO: Handle in if_expr
1135- mr_var_name := 'mr_${node.pos.pos} '
1136- mut is_option := return_type.has_flag (.option)
1137- mut mr_styp := g.styp (return_type.clear_flag (.result))
1135+ mut ret_type := return_type
1136+ mut ret_sym := return_sym
1137+ mut suffix := ''
1138+ if g.comptime.inside_comptime_for && node.right[0 ] is ast.CallExpr {
1139+ call_expr := node.right[0 ] as ast.CallExpr
1140+ if call_expr.concrete_types.len > 0 && return_sym.info is ast.MultiReturn
1141+ && g.comptime.comptime_for_field_var != '' {
1142+ field_type := g.comptime.comptime_for_field_type
1143+ field_sym := g.table.sym (field_type)
1144+ if field_sym.info is ast.Map {
1145+ map_info := field_sym.info as ast.Map
1146+ ret_type = g.table.find_or_register_multi_return ([map_info.key_type, map_info.value_type])
1147+ ret_sym = * g.table.sym (ret_type)
1148+ }
1149+ }
1150+ if g.comptime.comptime_for_field_var != '' {
1151+ suffix = '_${g.comptime.comptime_for_field_value.name} '
1152+ }
1153+ }
1154+ mr_var_name := 'mr_${node.pos.pos}${suffix} '
1155+ mut is_option := ret_type.has_flag (.option)
1156+ mut mr_styp := g.styp (ret_type.clear_flag (.result))
11381157 if node.right[0 ] is ast.CallExpr && node.right[0 ].or_block.kind != .absent {
11391158 is_option = false
1140- mr_styp = g.styp (return_type .clear_option_and_result ())
1159+ mr_styp = g.styp (ret_type .clear_option_and_result ())
11411160 }
11421161 g.write ('${mr_styp} ${mr_var_name} = ' )
11431162 g.expr (node.right[0 ])
11441163 g.writeln (';' )
1145- mr_types := (return_sym.info as ast.MultiReturn ).types
1164+ mr_types := (ret_sym.info as ast.MultiReturn ).types
1165+ mut recompute_types := false
1166+ if g.comptime.inside_comptime_for && node.right[0 ] is ast.CallExpr {
1167+ call_expr := node.right[0 ] as ast.CallExpr
1168+ if call_expr.concrete_types.len > 0 && g.comptime.comptime_for_field_var != ''
1169+ && return_sym.info is ast.MultiReturn {
1170+ recompute_types = true
1171+ for i, mut lx in & node.left {
1172+ if mut lx is ast.Ident && lx.kind != .blank_ident {
1173+ if mut lx.obj is ast.Var {
1174+ lx.obj.typ = mr_types[i]
1175+ }
1176+ }
1177+ }
1178+ }
1179+ }
11461180 for i, lx in node.left {
11471181 mut cur_indexexpr := - 1
11481182 mut is_auto_heap := false
@@ -1161,7 +1195,8 @@ fn (mut g Gen) gen_multi_return_assign(node &ast.AssignStmt, return_type ast.Typ
11611195 if lx is ast.IndexExpr && g.cur_indexexpr.len > 0 {
11621196 cur_indexexpr = g.cur_indexexpr.index (lx.pos.pos)
11631197 }
1164- styp := if ident.name in g.defer_vars { '' } else { g.styp (node.left_types[i]) }
1198+ left_type := if recompute_types { mr_types[i] } else { node.left_types[i] }
1199+ styp := if ident.name in g.defer_vars { '' } else { g.styp (left_type) }
11651200 if node.op == .decl_assign {
11661201 g.write ('${styp} ' )
11671202 }
@@ -1170,14 +1205,14 @@ fn (mut g Gen) gen_multi_return_assign(node &ast.AssignStmt, return_type ast.Typ
11701205 }
11711206 noscan := if is_auto_heap { g.check_noscan (return_type) } else { '' }
11721207 mut aligned := 0
1173- sym := g.table.final_sym (node.left_types[i] )
1208+ sym := g.table.final_sym (left_type )
11741209 if sym.info is ast.Struct {
11751210 if attr := sym.info.attrs.find_first ('aligned' ) {
11761211 aligned = if attr.arg == '' { 0 } else { attr.arg.int () }
11771212 }
11781213 }
1179- if node.left_types[i] .has_flag (.option) {
1180- base_typ := g.base_type (node.left_types[i] )
1214+ if left_type .has_flag (.option) {
1215+ base_typ := g.base_type (left_type )
11811216 tmp_var := if is_auto_heap {
11821217 if aligned != 0 {
11831218 'HEAP_align(${styp} , ${mr_var_name} .arg${i} , ${aligned} )'
0 commit comments