diff options
| author | Jacob Young <jacobly0@users.noreply.github.com> | 2023-06-02 01:15:36 -0400 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2023-06-10 20:47:59 -0700 |
| commit | 04e66e6b4deb67aef9a4064decd82a678cb7ec82 (patch) | |
| tree | 85c7c8127147467d13707adbc255fc1239b1b7f6 /src/InternPool.zig | |
| parent | fdfe730487972f089786938706f311b1f8631333 (diff) | |
| download | zig-04e66e6b4deb67aef9a4064decd82a678cb7ec82.tar.gz zig-04e66e6b4deb67aef9a4064decd82a678cb7ec82.zip | |
InternPool: add optional coercion
Diffstat (limited to 'src/InternPool.zig')
| -rw-r--r-- | src/InternPool.zig | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/src/InternPool.zig b/src/InternPool.zig index ecdd30d110..801e351b4e 100644 --- a/src/InternPool.zig +++ b/src/InternPool.zig @@ -4614,18 +4614,27 @@ pub fn getCoerced(ip: *InternPool, gpa: Allocator, val: Index, new_ty: Index) Al .int => |int| return ip.getCoerced(gpa, int, new_ty), else => {}, }, - .opt => |opt| if (ip.isPointerType(new_ty)) - return switch (opt.val) { + .opt => |opt| switch (ip.indexToKey(new_ty)) { + .ptr_type => |ptr_type| return switch (opt.val) { .none => try ip.get(gpa, .{ .ptr = .{ .ty = new_ty, .addr = .{ .int = .zero_usize }, - .len = switch (ip.indexToKey(new_ty).ptr_type.flags.size) { + .len = switch (ptr_type.flags.size) { .One, .Many, .C => .none, .Slice => try ip.get(gpa, .{ .undef = .usize_type }), }, } }), else => |payload| try ip.getCoerced(gpa, payload, new_ty), }, + .opt_type => |child_type| return try ip.get(gpa, .{ .opt = .{ + .ty = new_ty, + .val = switch (opt.val) { + .none => .none, + else => try ip.getCoerced(gpa, opt.val, child_type), + }, + } }), + else => {}, + }, .err => |err| if (ip.isErrorSetType(new_ty)) return ip.get(gpa, .{ .err = .{ .ty = new_ty, |
