@@ -94,9 +94,9 @@ fn (mut t Transformer) try_lower_array_repeat_call(_id flat.NodeId, node flat.No
9494 return t.make_call_expr_typed (selector, [count, t.make_int_literal (depth)], node.typ)
9595}
9696
97- // make_plain_array_repeat_value preserves the repeated result before destroying a
98- // non-addressable source array whose backing storage was materialized after ownership
99- // analysis .
97+ // make_plain_array_repeat_value preserves the repeated result before freeing the backing
98+ // storage of a non-addressable source array materialized after ownership analysis. The
99+ // repeated result owns the shallow-copied elements, so the source elements must not be dropped .
100100fn (mut t Transformer) make_plain_array_repeat_value (base_id flat.NodeId, count_id flat.NodeId, array_type string ) flat.NodeId {
101101 source := t.transform_expr (base_id)
102102 stable_source := t.stable_transformed_expr_for_reuse (source, array_type,
@@ -108,9 +108,7 @@ fn (mut t Transformer) make_plain_array_repeat_value(base_id flat.NodeId, count_
108108 array_type)
109109 out_name := t.new_temp ('plain_array_repeat' )
110110 t.pending_stmts << t.make_decl_assign_typed (out_name, repeated, array_type)
111- t.pending_stmts << t.make_expr_stmt (t.make_call_typed ('drop_owned' , [
112- stable_source,
113- ], 'void' ))
111+ t.pending_stmts << t.make_expr_stmt (t.make_method_call (stable_source, 'free' , []flat.NodeId{}))
114112 result := t.make_ident (out_name)
115113 t.set_node_typ (int (result), array_type)
116114 return result
0 commit comments