diff options
| author | Veikka Tuominen <git@vexu.eu> | 2022-09-29 15:04:07 +0300 |
|---|---|---|
| committer | Veikka Tuominen <git@vexu.eu> | 2022-09-30 00:09:24 +0300 |
| commit | 409cf4aeb826d8f7c35f0aa10bb0a8fe45188555 (patch) | |
| tree | b2b34588c5ec7b22c1c138cfe632c8f4eb6f2daf /test/behavior/slice.zig | |
| parent | 36d2a5503705b4da03dab9dbf724653895d2b641 (diff) | |
| download | zig-409cf4aeb826d8f7c35f0aa10bb0a8fe45188555.tar.gz zig-409cf4aeb826d8f7c35f0aa10bb0a8fe45188555.zip | |
Sema: use correct ptr ty to check for attributes of slice field ptr
Closes #12870
Closes #13006
Diffstat (limited to 'test/behavior/slice.zig')
| -rw-r--r-- | test/behavior/slice.zig | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/test/behavior/slice.zig b/test/behavior/slice.zig index e5cb8ea408..5aeb6a3414 100644 --- a/test/behavior/slice.zig +++ b/test/behavior/slice.zig @@ -684,3 +684,31 @@ test "slice len modification at comptime" { try expect(items[1] == 1); } } + +test "slice field ptr const" { + if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO + + const const_slice: []const u8 = "string"; + + const const_ptr_const_slice = &const_slice; + try expectEqual(*const []const u8, @TypeOf(&const_ptr_const_slice.*)); + try expectEqual(*const [*]const u8, @TypeOf(&const_ptr_const_slice.ptr)); + + var var_ptr_const_slice = &const_slice; + try expectEqual(*const []const u8, @TypeOf(&var_ptr_const_slice.*)); + try expectEqual(*const [*]const u8, @TypeOf(&var_ptr_const_slice.ptr)); +} + +test "slice field ptr var" { + if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO + + var var_slice: []const u8 = "string"; + + var var_ptr_var_slice = &var_slice; + try expectEqual(*[]const u8, @TypeOf(&var_ptr_var_slice.*)); + try expectEqual(*[*]const u8, @TypeOf(&var_ptr_var_slice.ptr)); + + const const_ptr_var_slice = &var_slice; + try expectEqual(*[]const u8, @TypeOf(&const_ptr_var_slice.*)); + try expectEqual(*[*]const u8, @TypeOf(&const_ptr_var_slice.ptr)); +} |
