| author | |
| committer | |
| log | 409cf4aeb826d8f7c35f0aa10bb0a8fe45188555 |
| tree | b2b34588c5ec7b22c1c138cfe632c8f4eb6f2daf |
| parent | 36d2a5503705b4da03dab9dbf724653895d2b641 |
Closes #12870
Closes #130062 files changed, 36 insertions(+), 4 deletions(-)
src/Sema.zig+8-4| ... | ... | @@ -21664,14 +21664,17 @@ fn fieldPtr( |
| 21664 | 21664 | else |
| 21665 | 21665 | object_ptr; |
| 21666 | 21666 | |
| 21667 | const attr_ptr_ty = if (is_pointer_to) object_ty else object_ptr_ty; | |
| 21668 | ||
| 21667 | 21669 | if (mem.eql(u8, field_name, "ptr")) { |
| 21668 | 21670 | const buf = try sema.arena.create(Type.SlicePtrFieldTypeBuffer); |
| 21669 | 21671 | const slice_ptr_ty = inner_ty.slicePtrFieldType(buf); |
| 21670 | 21672 | |
| 21671 | 21673 | const result_ty = try Type.ptr(sema.arena, sema.mod, .{ |
| 21672 | 21674 | .pointee_type = slice_ptr_ty, |
| 21673 | .mutable = object_ptr_ty.ptrIsMutable(), | |
| 21674 | .@"addrspace" = object_ptr_ty.ptrAddressSpace(), | |
| 21675 | .mutable = attr_ptr_ty.ptrIsMutable(), | |
| 21676 | .@"volatile" = attr_ptr_ty.isVolatilePtr(), | |
| 21677 | .@"addrspace" = attr_ptr_ty.ptrAddressSpace(), | |
| 21675 | 21678 | }); |
| 21676 | 21679 | |
| 21677 | 21680 | if (try sema.resolveDefinedValue(block, object_ptr_src, inner_ptr)) |val| { |
| ... | ... | @@ -21690,8 +21693,9 @@ fn fieldPtr( |
| 21690 | 21693 | } else if (mem.eql(u8, field_name, "len")) { |
| 21691 | 21694 | const result_ty = try Type.ptr(sema.arena, sema.mod, .{ |
| 21692 | 21695 | .pointee_type = Type.usize, |
| 21693 | .mutable = object_ptr_ty.ptrIsMutable(), | |
| 21694 | .@"addrspace" = object_ptr_ty.ptrAddressSpace(), | |
| 21696 | .mutable = attr_ptr_ty.ptrIsMutable(), | |
| 21697 | .@"volatile" = attr_ptr_ty.isVolatilePtr(), | |
| 21698 | .@"addrspace" = attr_ptr_ty.ptrAddressSpace(), | |
| 21695 | 21699 | }); |
| 21696 | 21700 | |
| 21697 | 21701 | if (try sema.resolveDefinedValue(block, object_ptr_src, inner_ptr)) |val| { |
test/behavior/slice.zig+28| ... | ... | @@ -684,3 +684,31 @@ test "slice len modification at comptime" { |
| 684 | 684 | try expect(items[1] == 1); |
| 685 | 685 | } |
| 686 | 686 | } |
| 687 | ||
| 688 | test "slice field ptr const" { | |
| 689 | if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO | |
| 690 | ||
| 691 | const const_slice: []const u8 = "string"; | |
| 692 | ||
| 693 | const const_ptr_const_slice = &const_slice; | |
| 694 | try expectEqual(*const []const u8, @TypeOf(&const_ptr_const_slice.*)); | |
| 695 | try expectEqual(*const [*]const u8, @TypeOf(&const_ptr_const_slice.ptr)); | |
| 696 | ||
| 697 | var var_ptr_const_slice = &const_slice; | |
| 698 | try expectEqual(*const []const u8, @TypeOf(&var_ptr_const_slice.*)); | |
| 699 | try expectEqual(*const [*]const u8, @TypeOf(&var_ptr_const_slice.ptr)); | |
| 700 | } | |
| 701 | ||
| 702 | test "slice field ptr var" { | |
| 703 | if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO | |
| 704 | ||
| 705 | var var_slice: []const u8 = "string"; | |
| 706 | ||
| 707 | var var_ptr_var_slice = &var_slice; | |
| 708 | try expectEqual(*[]const u8, @TypeOf(&var_ptr_var_slice.*)); | |
| 709 | try expectEqual(*[*]const u8, @TypeOf(&var_ptr_var_slice.ptr)); | |
| 710 | ||
| 711 | const const_ptr_var_slice = &var_slice; | |
| 712 | try expectEqual(*[]const u8, @TypeOf(&const_ptr_var_slice.*)); | |
| 713 | try expectEqual(*[*]const u8, @TypeOf(&const_ptr_var_slice.ptr)); | |
| 714 | } |