stage2: concat/mult of slices yields ptr to array
This commit is contained in:
committed by
Andrew Kelley
parent
23bae382c9
commit
6fc07f49a9
@@ -8643,7 +8643,7 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
|
||||
});
|
||||
const val = try Value.Tag.aggregate.create(anon_decl.arena(), buf);
|
||||
const decl = try anon_decl.finish(ty, val, 0);
|
||||
if (lhs_single_ptr or rhs_single_ptr) {
|
||||
if (lhs_ty.zigTypeTag() == .Pointer or rhs_ty.zigTypeTag() == .Pointer) {
|
||||
return sema.analyzeDeclRef(decl);
|
||||
} else {
|
||||
return sema.analyzeDeclVal(block, .unneeded, decl);
|
||||
@@ -8818,7 +8818,7 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
|
||||
break :blk try Value.Tag.aggregate.create(anon_decl.arena(), buf);
|
||||
};
|
||||
const decl = try anon_decl.finish(final_ty, val, 0);
|
||||
if (is_single_ptr) {
|
||||
if (lhs_ty.zigTypeTag() == .Pointer) {
|
||||
return sema.analyzeDeclRef(decl);
|
||||
} else {
|
||||
return sema.analyzeDeclVal(block, .unneeded, decl);
|
||||
|
||||
@@ -583,14 +583,27 @@ test "type coercion of pointer to anon struct literal to pointer to slice" {
|
||||
comptime try S.doTheTest();
|
||||
}
|
||||
|
||||
test "array concat of slices gives slice" {
|
||||
if (builtin.zig_backend != .stage1) return error.SkipZigTest; // TODO
|
||||
|
||||
test "array concat of slices gives ptr to array" {
|
||||
comptime {
|
||||
var a: []const u8 = "aoeu";
|
||||
var b: []const u8 = "asdf";
|
||||
const c = a ++ b;
|
||||
try expect(std.mem.eql(u8, c, "aoeuasdf"));
|
||||
if (builtin.zig_backend != .stage1) {
|
||||
// spec change: array concat now returns pointer-to-array for slices
|
||||
try expect(@TypeOf(c) == *const [8]u8);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
test "array mult of slice gives ptr to array" {
|
||||
if (builtin.zig_backend == .stage1) return error.SkipZigTest; // Stage 1 does not support multiplying slices
|
||||
|
||||
comptime {
|
||||
var a: []const u8 = "aoeu";
|
||||
const c = a ** 2;
|
||||
try expect(std.mem.eql(u8, c, "aoeuaoeu"));
|
||||
try expect(@TypeOf(c) == *const [8]u8);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user