| author | |
| committer | |
| log | 6fc07f49a9d723fba6422d83d23384a484b0b0be |
| tree | d2d03232347528bea81293a412bf83762e2a0283 |
| parent | 23bae382c983c7685396e1525216060db06f2e00 |
2 files changed, 18 insertions(+), 5 deletions(-)
src/Sema.zig+2-2| ... | @@ -8643,7 +8643,7 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -8643,7 +8643,7 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 8643 | }); | 8643 | }); |
| 8644 | const val = try Value.Tag.aggregate.create(anon_decl.arena(), buf); | 8644 | const val = try Value.Tag.aggregate.create(anon_decl.arena(), buf); |
| 8645 | const decl = try anon_decl.finish(ty, val, 0); | 8645 | const decl = try anon_decl.finish(ty, val, 0); |
| 8646 | if (lhs_single_ptr or rhs_single_ptr) { | 8646 | if (lhs_ty.zigTypeTag() == .Pointer or rhs_ty.zigTypeTag() == .Pointer) { |
| 8647 | return sema.analyzeDeclRef(decl); | 8647 | return sema.analyzeDeclRef(decl); |
| 8648 | } else { | 8648 | } else { |
| 8649 | return sema.analyzeDeclVal(block, .unneeded, decl); | 8649 | return sema.analyzeDeclVal(block, .unneeded, decl); |
| ... | @@ -8818,7 +8818,7 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -8818,7 +8818,7 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 8818 | break :blk try Value.Tag.aggregate.create(anon_decl.arena(), buf); | 8818 | break :blk try Value.Tag.aggregate.create(anon_decl.arena(), buf); |
| 8819 | }; | 8819 | }; |
| 8820 | const decl = try anon_decl.finish(final_ty, val, 0); | 8820 | const decl = try anon_decl.finish(final_ty, val, 0); |
| 8821 | if (is_single_ptr) { | 8821 | if (lhs_ty.zigTypeTag() == .Pointer) { |
| 8822 | return sema.analyzeDeclRef(decl); | 8822 | return sema.analyzeDeclRef(decl); |
| 8823 | } else { | 8823 | } else { |
| 8824 | return sema.analyzeDeclVal(block, .unneeded, decl); | 8824 | return sema.analyzeDeclVal(block, .unneeded, decl); |
test/behavior/slice.zig+16-3| ... | @@ -583,14 +583,27 @@ test "type coercion of pointer to anon struct literal to pointer to slice" { | ... | @@ -583,14 +583,27 @@ test "type coercion of pointer to anon struct literal to pointer to slice" { |
| 583 | comptime try S.doTheTest(); | 583 | comptime try S.doTheTest(); |
| 584 | } | 584 | } |
| 585 | 585 | ||
| 586 | test "array concat of slices gives slice" { | 586 | test "array concat of slices gives ptr to array" { |
| 587 | if (builtin.zig_backend != .stage1) return error.SkipZigTest; // TODO | ||
| 588 | |||
| 589 | comptime { | 587 | comptime { |
| 590 | var a: []const u8 = "aoeu"; | 588 | var a: []const u8 = "aoeu"; |
| 591 | var b: []const u8 = "asdf"; | 589 | var b: []const u8 = "asdf"; |
| 592 | const c = a ++ b; | 590 | const c = a ++ b; |
| 593 | try expect(std.mem.eql(u8, c, "aoeuasdf")); | 591 | try expect(std.mem.eql(u8, c, "aoeuasdf")); |
| 592 | if (builtin.zig_backend != .stage1) { | ||
| 593 | // spec change: array concat now returns pointer-to-array for slices | ||
| 594 | try expect(@TypeOf(c) == *const [8]u8); | ||
| 595 | } | ||
| 596 | } | ||
| 597 | } | ||
| 598 | |||
| 599 | test "array mult of slice gives ptr to array" { | ||
| 600 | if (builtin.zig_backend == .stage1) return error.SkipZigTest; // Stage 1 does not support multiplying slices | ||
| 601 | |||
| 602 | comptime { | ||
| 603 | var a: []const u8 = "aoeu"; | ||
| 604 | const c = a ** 2; | ||
| 605 | try expect(std.mem.eql(u8, c, "aoeuaoeu")); | ||
| 606 | try expect(@TypeOf(c) == *const [8]u8); | ||
| 594 | } | 607 | } |
| 595 | } | 608 | } |
| 596 | 609 |