| ... | ... | @@ -17085,6 +17085,47 @@ fn resolvePeerTypes( |
| 17085 | 17085 | } |
| 17086 | 17086 | } |
| 17087 | 17087 | |
| 17088 | // *[N]T to []T (prev is slice) |
| 17089 | if (chosen_ty.isSlice() and |
| 17090 | candidate_ty.ptrSize() == .One and |
| 17091 | candidate_ty.childType().zigTypeTag() == .Array) |
| 17092 | { |
| 17093 | const chosen_elem_ty = chosen_ty.elemType2(); |
| 17094 | const candidate_elem_ty = candidate_ty.childType().elemType2(); |
| 17095 | if ((try sema.coerceInMemoryAllowed(block, candidate_elem_ty, chosen_elem_ty, false, target, src, src)) == .ok) { |
| 17096 | convert_to_slice = false; // it already is a slice |
| 17097 | |
| 17098 | // If the pointer is const then we need to const |
| 17099 | if (candidate_ty.childType().isConstPtr()) |
| 17100 | make_the_slice_const = true; |
| 17101 | |
| 17102 | continue; |
| 17103 | } |
| 17104 | } |
| 17105 | |
| 17106 | // *[N]T to []T (current is slice) |
| 17107 | if (chosen_ty_tag == .Pointer and |
| 17108 | chosen_ty.ptrSize() == .One and |
| 17109 | chosen_ty.childType().zigTypeTag() == .Array and |
| 17110 | candidate_ty.isSlice()) |
| 17111 | { |
| 17112 | const chosen_child_ty = chosen_ty.childType(); |
| 17113 | const chosen_elem_ty = chosen_child_ty.elemType2(); |
| 17114 | const candidate_elem_ty = candidate_ty.elemType2(); |
| 17115 | if ((try sema.coerceInMemoryAllowed(block, candidate_elem_ty, chosen_elem_ty, false, target, src, src)) == .ok) { |
| 17116 | chosen = candidate; |
| 17117 | chosen_i = candidate_i + 1; |
| 17118 | |
| 17119 | convert_to_slice = false; // it already is a slice |
| 17120 | |
| 17121 | // If the prev pointer is const then we need to const |
| 17122 | if (chosen_child_ty.isConstPtr()) |
| 17123 | make_the_slice_const = true; |
| 17124 | |
| 17125 | continue; |
| 17126 | } |
| 17127 | } |
| 17128 | |
| 17088 | 17129 | // *[N]T and *[M]T |
| 17089 | 17130 | // verify both are pointers to known lengths |
| 17090 | 17131 | if (chosen_ty_tag == .Pointer and |
| ... | ... | @@ -17222,6 +17263,15 @@ fn resolvePeerTypes( |
| 17222 | 17263 | return Type.ptr(sema.arena, info.data); |
| 17223 | 17264 | } |
| 17224 | 17265 | |
| 17266 | if (make_the_slice_const) { |
| 17267 | // turn []T => []const T |
| 17268 | var info = chosen_ty.ptrInfo(); |
| 17269 | info.data.mutable = false; |
| 17270 | |
| 17271 | std.debug.print("TYPE: {}\n", .{Type.ptr(sema.arena, info.data)}); |
| 17272 | return Type.ptr(sema.arena, info.data); |
| 17273 | } |
| 17274 | |
| 17225 | 17275 | return chosen_ty; |
| 17226 | 17276 | } |
| 17227 | 17277 | |