diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2021-10-03 12:49:57 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2021-10-03 12:49:57 -0700 |
| commit | 86c265aec8b9cdca0e78bfb02d7442e79c0be5a9 (patch) | |
| tree | a2c606991de931f0f74f0a2ce87ca51cd1dc08a3 /src | |
| parent | c4df9bf56f204f63f4e87255933ba453d69d0182 (diff) | |
| download | zig-86c265aec8b9cdca0e78bfb02d7442e79c0be5a9.tar.gz zig-86c265aec8b9cdca0e78bfb02d7442e79c0be5a9.zip | |
stage2: Type: fix eql impl for error unions
Also implement renderFullyQualifiedName.
Diffstat (limited to 'src')
| -rw-r--r-- | src/type.zig | 83 |
1 files changed, 80 insertions, 3 deletions
diff --git a/src/type.zig b/src/type.zig index 8f200c0f35..94808f2b9a 100644 --- a/src/type.zig +++ b/src/type.zig @@ -580,9 +580,15 @@ pub const Type = extern union { return a.tag() == b.tag(); }, .ErrorUnion => { - const a_data = a.castTag(.error_union).?.data; - const b_data = b.castTag(.error_union).?.data; - return a_data.error_set.eql(b_data.error_set) and a_data.payload.eql(b_data.payload); + const a_set = a.errorUnionSet(); + const b_set = b.errorUnionSet(); + if (!a_set.eql(b_set)) return false; + + const a_payload = a.errorUnionPayload(); + const b_payload = b.errorUnionPayload(); + if (!a_payload.eql(b_payload)) return false; + + return true; }, .ErrorSet => { if (a.tag() == .anyerror and b.tag() == .anyerror) { @@ -890,6 +896,77 @@ pub const Type = extern union { return Type{ .ptr_otherwise = &new_payload.base }; } + pub fn renderFullyQualifiedName(ty: Type, writer: anytype) !void { + const t = ty.tag(); + switch (t) { + .u1, + .u8, + .i8, + .u16, + .i16, + .u32, + .i32, + .u64, + .i64, + .u128, + .i128, + .usize, + .isize, + .c_short, + .c_ushort, + .c_int, + .c_uint, + .c_long, + .c_ulong, + .c_longlong, + .c_ulonglong, + .c_longdouble, + .c_void, + .f16, + .f32, + .f64, + .f128, + .bool, + .void, + .type, + .anyerror, + .@"anyframe", + .comptime_int, + .comptime_float, + .noreturn, + .var_args_param, + .bound_fn, + => return writer.writeAll(@tagName(t)), + + .enum_literal => return writer.writeAll("@Type(.EnumLiteral)"), + .@"null" => return writer.writeAll("@Type(.Null)"), + .@"undefined" => return writer.writeAll("@Type(.Undefined)"), + + .@"struct" => { + const struct_obj = ty.castTag(.@"struct").?.data; + return struct_obj.owner_decl.renderFullyQualifiedName(writer); + }, + .@"union", .union_tagged => { + const union_obj = ty.cast(Payload.Union).?.data; + return union_obj.owner_decl.renderFullyQualifiedName(writer); + }, + .enum_full, .enum_nonexhaustive => { + const enum_full = ty.cast(Payload.EnumFull).?.data; + return enum_full.owner_decl.renderFullyQualifiedName(writer); + }, + .enum_simple => { + const enum_simple = ty.castTag(.enum_simple).?.data; + return enum_simple.owner_decl.renderFullyQualifiedName(writer); + }, + .enum_numbered => { + const enum_numbered = ty.castTag(.enum_numbered).?.data; + return enum_numbered.owner_decl.renderFullyQualifiedName(writer); + }, + .@"opaque" => @panic("TODO"), + else => unreachable, + } + } + pub fn format( start_type: Type, comptime fmt: []const u8, |
