compiler: provide correct result types to += and -=

Resolves: #21341
This commit is contained in:
mlugg
2024-09-15 15:45:20 +01:00
parent 5d7fa5513f
commit 1365be5d02
5 changed files with 80 additions and 2 deletions

View File

@@ -98,6 +98,21 @@ test "pointer subtraction" {
}
}
test "pointer arithmetic with non-trivial RHS" {
var t: bool = undefined;
t = true;
var ptr: [*]const u8 = "Hello, World!";
ptr += if (t) 5 else 2;
try expect(ptr[0] == ',');
ptr += if (!t) 4 else 2;
try expect(ptr[0] == 'W');
ptr -= if (t) @as(usize, 6) else 3;
try expect(ptr[0] == 'e');
ptr -= if (!t) @as(usize, 0) else 1;
try expect(ptr[0] == 'H');
}
test "double pointer parsing" {
comptime assert(PtrOf(PtrOf(i32)) == **i32);
}