| author | |
| committer | |
| log | 943ee59bb1524a46dd13af6a55d30025e25dd061 |
| tree | 0be2e741270decbc11aaf96da2a3e573aef02813 |
| parent | e442f88b767a2b70a7e396501453013d0a364974 |
| signature |
2 files changed, 41 insertions(+), 0 deletions(-)
src/Sema.zig+29| ... | ... | @@ -17109,6 +17109,35 @@ fn resolvePeerTypes( |
| 17109 | 17109 | } |
| 17110 | 17110 | } |
| 17111 | 17111 | |
| 17112 | // *[N]T to [*]T | |
| 17113 | if (candidate_ty.ptrSize() == .Many and | |
| 17114 | chosen_ty_tag == .Pointer and | |
| 17115 | chosen_ty.ptrSize() == .One and | |
| 17116 | chosen_ty.childType().zigTypeTag() == .Array) | |
| 17117 | { | |
| 17118 | chosen = candidate; | |
| 17119 | chosen_i = candidate_i + 1; | |
| 17120 | ||
| 17121 | convert_to_slice = false; | |
| 17122 | ||
| 17123 | if (chosen_ty.childType().isConstPtr() and !candidate_ty.childType().isConstPtr()) | |
| 17124 | make_the_slice_const = true; | |
| 17125 | ||
| 17126 | continue; | |
| 17127 | } | |
| 17128 | ||
| 17129 | // *[N]T to [*]T (prev is many pointer) | |
| 17130 | if (candidate_ty.ptrSize() == .One and | |
| 17131 | candidate_ty.childType().zigTypeTag() == .Array and | |
| 17132 | chosen_ty_tag == .Pointer and | |
| 17133 | chosen_ty.ptrSize() == .Many) | |
| 17134 | { | |
| 17135 | if (candidate_ty.childType().isConstPtr() and !chosen_ty.childType().isConstPtr()) | |
| 17136 | make_the_slice_const = true; | |
| 17137 | ||
| 17138 | continue; | |
| 17139 | } | |
| 17140 | ||
| 17112 | 17141 | // *[N]T to []T (prev is slice) |
| 17113 | 17142 | // *[N]T to E![]T |
| 17114 | 17143 | if ((chosen_ty.isSlice() or (chosen_ty_tag == .ErrorUnion and chosen_ty.errorUnionPayload().isSlice())) and |
test/behavior/cast.zig+12| ... | ... | @@ -643,6 +643,18 @@ test "peer cast *[0]T to []const T" { |
| 643 | 643 | try expect(mem.eql(u8, "abcde", y)); |
| 644 | 644 | } |
| 645 | 645 | |
| 646 | test "peer cast *[N]T to [*]T" { | |
| 647 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; | |
| 648 | if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO | |
| 649 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | |
| 650 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO | |
| 651 | ||
| 652 | var array = [4:99]i32{ 1, 2, 3, 4 }; | |
| 653 | var dest: [*]i32 = undefined; | |
| 654 | try expect(@TypeOf(&array, dest) == [*]i32); | |
| 655 | try expect(@TypeOf(dest, &array) == [*]i32); | |
| 656 | } | |
| 657 | ||
| 646 | 658 | test "peer resolution of string literals" { |
| 647 | 659 | if (builtin.zig_backend != .stage1) return error.SkipZigTest; // TODO |
| 648 | 660 |