Skip to content

Commit 173ad11

Browse files
xdBronchTechatrix
authored andcommitted
deduplicate errors when resolving error sets
1 parent f707494 commit 173ad11

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

src/analysis.zig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2113,7 +2113,7 @@ fn resolveTypeOfNodeUncached(analyser: *Analyser, options: ResolveOptions) error
21132113

21142114
.error_set_decl => {
21152115
const lbrace, const rbrace = tree.nodeData(node).token_and_token;
2116-
var strings: std.ArrayList(InternPool.String) = .empty;
2116+
var strings: std.AutoArrayHashMapUnmanaged(InternPool.String, void) = .empty;
21172117
defer strings.deinit(analyser.gpa);
21182118
var i: usize = 0;
21192119
for (lbrace + 1..rbrace) |tok_i| {
@@ -2122,9 +2122,9 @@ fn resolveTypeOfNodeUncached(analyser: *Analyser, options: ResolveOptions) error
21222122
defer i += 1;
21232123
const name = offsets.tokenToSlice(tree, identifier_token);
21242124
const index = try analyser.ip.string_pool.getOrPutString(analyser.gpa, name);
2125-
try strings.append(analyser.gpa, index);
2125+
try strings.put(analyser.gpa, index, {});
21262126
}
2127-
const names = try analyser.ip.getStringSlice(analyser.gpa, strings.items);
2127+
const names = try analyser.ip.getStringSlice(analyser.gpa, strings.keys());
21282128
const ip_index = try analyser.ip.get(analyser.gpa, .{ .error_set_type = .{ .owner_decl = .none, .names = names } });
21292129
return Type.fromIP(analyser, .type_type, ip_index);
21302130
},

tests/analysis/error_union.zig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,6 @@ const ErrorUnionType = Error!u32;
66
const InvalidErrorUnionTypeUnwrap = ErrorUnionType catch |err| err;
77
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^ (unknown)()
88
// ^^^ (unknown)()
9+
10+
const DuplicateErrorName = error{ Foo, Foo } || error{Bar};
11+
// ^^^^^^^^^^^^^^^^^^ (type)(error{Foo,Bar})

0 commit comments

Comments
 (0)