mirror of
https://github.com/ziglang/zig.git
synced 2026-01-03 03:53:20 +00:00
Sema: allow empty end index in zirSliceSentinel
This fixes a regression, and enables some related behavior tests which were accidentally disabled.
This commit is contained in:
parent
45e9617720
commit
57f6e6729f
@ -10069,7 +10069,7 @@ fn zirSliceSentinel(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr
|
||||
const extra = sema.code.extraData(Zir.Inst.SliceSentinel, inst_data.payload_index).data;
|
||||
const array_ptr = try sema.resolveInst(extra.lhs);
|
||||
const start = try sema.resolveInst(extra.start);
|
||||
const end = try sema.resolveInst(extra.end);
|
||||
const end: Air.Inst.Ref = if (extra.end == .none) .none else try sema.resolveInst(extra.end);
|
||||
const sentinel = try sema.resolveInst(extra.sentinel);
|
||||
const ptr_src: LazySrcLoc = .{ .node_offset_slice_ptr = inst_data.src_node };
|
||||
const start_src: LazySrcLoc = .{ .node_offset_slice_start = inst_data.src_node };
|
||||
|
||||
@ -378,12 +378,16 @@ test "slice syntax resulting in pointer-to-array" {
|
||||
try testPointer0();
|
||||
try testPointerAlign();
|
||||
try testSlice();
|
||||
try testSliceZ();
|
||||
try testSliceOpt();
|
||||
try testSliceAlign();
|
||||
try testConcatStrLiterals();
|
||||
try testSliceLength();
|
||||
try testSliceLengthZ();
|
||||
try testArrayLength();
|
||||
try testArrayLengthZ();
|
||||
try testMultiPointer();
|
||||
try testMultiPointerLengthZ();
|
||||
}
|
||||
|
||||
fn testArray() !void {
|
||||
@ -469,8 +473,12 @@ test "slice syntax resulting in pointer-to-array" {
|
||||
var array = [5:0]u8{ 1, 2, 3, 4, 5 };
|
||||
var slice: [:0]u8 = &array;
|
||||
try comptime expect(@TypeOf(slice[1..3]) == *[2]u8);
|
||||
try comptime expect(@TypeOf(slice[1..]) == [:0]u8);
|
||||
try comptime expect(@TypeOf(slice[1..3 :4]) == *[2:4]u8);
|
||||
if (@inComptime()) {
|
||||
try comptime expect(@TypeOf(slice[1..]) == *[4:0]u8);
|
||||
} else {
|
||||
try comptime expect(@TypeOf(slice[1..]) == [:0]u8);
|
||||
}
|
||||
}
|
||||
|
||||
fn testSliceOpt() !void {
|
||||
@ -491,8 +499,8 @@ test "slice syntax resulting in pointer-to-array" {
|
||||
}
|
||||
|
||||
fn testConcatStrLiterals() !void {
|
||||
try expectEqualSlices("a"[0..] ++ "b"[0..], "ab");
|
||||
try expectEqualSlices("a"[0.. :0] ++ "b"[0.. :0], "ab");
|
||||
try expectEqualSlices(u8, "ab", "a"[0..] ++ "b"[0..]);
|
||||
try expectEqualSlices(u8, "ab", "a"[0.. :0] ++ "b"[0.. :0]);
|
||||
}
|
||||
|
||||
fn testSliceLength() !void {
|
||||
@ -541,18 +549,18 @@ test "slice syntax resulting in pointer-to-array" {
|
||||
var array = [5:0]u8{ 1, 2, 3, 4, 5 };
|
||||
var ptr: [*]u8 = &array;
|
||||
try comptime expect(@TypeOf(ptr[1..][0..2]) == *[2]u8);
|
||||
try comptime expect(@TypeOf(ptr[1..][0..4]) == *[4:0]u8);
|
||||
try comptime expect(@TypeOf(ptr[1..][0..4]) == *[4]u8);
|
||||
try comptime expect(@TypeOf(ptr[1..][0..2 :4]) == *[2:4]u8);
|
||||
try comptime expect(@TypeOf(ptr[1.. :0][0..2]) == *[2]u8);
|
||||
try comptime expect(@TypeOf(ptr[1.. :0][0..4]) == *[4:0]u8);
|
||||
try comptime expect(@TypeOf(ptr[1.. :0][0..4]) == *[4]u8);
|
||||
try comptime expect(@TypeOf(ptr[1.. :0][0..2 :4]) == *[2:4]u8);
|
||||
|
||||
var ptr_z: [*:0]u8 = &array;
|
||||
try comptime expect(@TypeOf(ptr_z[1..][0..2]) == *[2]u8);
|
||||
try comptime expect(@TypeOf(ptr_z[1..][0..4]) == *[4:0]u8);
|
||||
try comptime expect(@TypeOf(ptr_z[1..][0..4]) == *[4]u8);
|
||||
try comptime expect(@TypeOf(ptr_z[1..][0..2 :4]) == *[2:4]u8);
|
||||
try comptime expect(@TypeOf(ptr_z[1.. :0][0..2]) == *[2]u8);
|
||||
try comptime expect(@TypeOf(ptr_z[1.. :0][0..4]) == *[4:0]u8);
|
||||
try comptime expect(@TypeOf(ptr_z[1.. :0][0..4]) == *[4]u8);
|
||||
try comptime expect(@TypeOf(ptr_z[1.. :0][0..2 :4]) == *[2:4]u8);
|
||||
}
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user