diff options
| author | Jacob Young <jacobly0@users.noreply.github.com> | 2023-05-29 20:52:53 -0400 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2023-06-10 20:47:56 -0700 |
| commit | 66ae42bb72a9ad4b1cd44b32fa5be322b07a5ffb (patch) | |
| tree | 565d5713d56669aa437aeaac56ccbe47444008ff /src/InternPool.zig | |
| parent | 55cda9a592dd5aa030d1134351394e1014fefed1 (diff) | |
| download | zig-66ae42bb72a9ad4b1cd44b32fa5be322b07a5ffb.tar.gz zig-66ae42bb72a9ad4b1cd44b32fa5be322b07a5ffb.zip | |
Sema: fix pointer arithmetic on single array pointers
Diffstat (limited to 'src/InternPool.zig')
| -rw-r--r-- | src/InternPool.zig | 48 |
1 files changed, 25 insertions, 23 deletions
diff --git a/src/InternPool.zig b/src/InternPool.zig index f8b71ffc06..1cb2704054 100644 --- a/src/InternPool.zig +++ b/src/InternPool.zig @@ -3352,30 +3352,32 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index { }, .elem, .field => |base_index| { const base_ptr_type = ip.indexToKey(ip.typeOf(base_index.base)).ptr_type; - switch (base_ptr_type.size) { - .One => switch (ip.indexToKey(base_ptr_type.elem_type)) { - .array_type, .vector_type => assert(ptr.addr == .elem), - .anon_struct_type => |anon_struct_type| { - assert(ptr.addr == .field); - assert(base_index.index < anon_struct_type.types.len); - }, - .struct_type => |struct_type| { - assert(ptr.addr == .field); - assert(base_index.index < ip.structPtrUnwrapConst(struct_type.index).?.fields.count()); - }, - .union_type => |union_type| { - assert(ptr.addr == .field); - assert(base_index.index < ip.unionPtrConst(union_type.index).fields.count()); - }, - .ptr_type => |slice_type| { - assert(ptr.addr == .field); - assert(slice_type.size == .Slice); - assert(base_index.index < 2); - }, - else => unreachable, + switch (ptr.addr) { + .elem => assert(base_ptr_type.size == .Many), + .field => { + assert(base_ptr_type.size == .One); + switch (ip.indexToKey(base_ptr_type.elem_type)) { + .anon_struct_type => |anon_struct_type| { + assert(ptr.addr == .field); + assert(base_index.index < anon_struct_type.types.len); + }, + .struct_type => |struct_type| { + assert(ptr.addr == .field); + assert(base_index.index < ip.structPtrUnwrapConst(struct_type.index).?.fields.count()); + }, + .union_type => |union_type| { + assert(ptr.addr == .field); + assert(base_index.index < ip.unionPtrConst(union_type.index).fields.count()); + }, + .ptr_type => |slice_type| { + assert(ptr.addr == .field); + assert(slice_type.size == .Slice); + assert(base_index.index < 2); + }, + else => unreachable, + } }, - .Many => assert(ptr.addr == .elem), - .Slice, .C => unreachable, + else => unreachable, } _ = ip.map.pop(); const index_index = try ip.get(gpa, .{ .int = .{ |
