diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2022-03-01 01:22:50 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-03-01 01:22:50 -0500 |
| commit | eaf1c97ce80606505768b8dd8daf8b479aec91a7 (patch) | |
| tree | a4f38b1e2150b5d2a88c66d2d96c23b9dd39775c /src/type.zig | |
| parent | d5131e91eba9324eda3a2ae47eb2aa4530c87e83 (diff) | |
| parent | 4763fd1a41bc5f6bb59b5c3c079069b84f19305a (diff) | |
| download | zig-eaf1c97ce80606505768b8dd8daf8b479aec91a7.tar.gz zig-eaf1c97ce80606505768b8dd8daf8b479aec91a7.zip | |
Merge pull request #11010 from mitchellh/peer-errors
stage2: peer resolve error sets and error unions
Diffstat (limited to 'src/type.zig')
| -rw-r--r-- | src/type.zig | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/type.zig b/src/type.zig index dbb5eb4ba3..96b8a78dea 100644 --- a/src/type.zig +++ b/src/type.zig @@ -4216,6 +4216,23 @@ pub const Type = extern union { }; } + /// Merge lhs with rhs. + /// Asserts that lhs and rhs are both error sets and are resolved. + pub fn errorSetMerge(lhs: Type, arena: Allocator, rhs: Type) !Type { + const lhs_names = lhs.errorSetNames(); + const rhs_names = rhs.errorSetNames(); + var names: Module.ErrorSet.NameMap = .{}; + try names.ensureUnusedCapacity(arena, lhs_names.len); + for (lhs_names) |name| { + names.putAssumeCapacityNoClobber(name, {}); + } + for (rhs_names) |name| { + try names.put(arena, name, {}); + } + + return try Tag.error_set_merged.create(arena, names); + } + pub fn enumFields(ty: Type) Module.EnumFull.NameMap { return switch (ty.tag()) { .enum_full, .enum_nonexhaustive => ty.cast(Payload.EnumFull).?.data.fields, |
