diff options
| author | mlugg <mlugg@mlugg.co.uk> | 2024-09-15 15:45:20 +0100 |
|---|---|---|
| committer | mlugg <mlugg@mlugg.co.uk> | 2024-09-16 16:42:42 +0100 |
| commit | 1365be5d02429dbbbfab43133d399b2af42047c5 (patch) | |
| tree | 2cb61dabb88b84094701df907ad67479951f53a8 /test/behavior | |
| parent | 5d7fa5513f92a43a418e3c5c4d27f0b61db313ff (diff) | |
| download | zig-1365be5d02429dbbbfab43133d399b2af42047c5.tar.gz zig-1365be5d02429dbbbfab43133d399b2af42047c5.zip | |
compiler: provide correct result types to `+=` and `-=`
Resolves: #21341
Diffstat (limited to 'test/behavior')
| -rw-r--r-- | test/behavior/pointers.zig | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/test/behavior/pointers.zig b/test/behavior/pointers.zig index 07041e70a1..bf0d37cc2b 100644 --- a/test/behavior/pointers.zig +++ b/test/behavior/pointers.zig @@ -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); } |
