Skip to content

Commit fe03b5d

Browse files
Resolve type of else capture in tagged union switch
1 parent 8f109a4 commit fe03b5d

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/analysis.zig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5512,6 +5512,14 @@ pub const DeclWithHandle = struct {
55125512
if (switch_expr_type.isEnumType()) break :blk switch_expr_type;
55135513
if (!switch_expr_type.isUnionType()) return switch_expr_type;
55145514

5515+
if (case.ast.values.len == 0) {
5516+
if (case.inline_token == null) {
5517+
return switch_expr_type;
5518+
}
5519+
// TODO either type
5520+
return null;
5521+
}
5522+
55155523
// TODO Peer type resolution, we just use the first resolvable item for now.
55165524
for (case.ast.values) |case_value| {
55175525
if (tree.nodeTag(case_value) != .enum_literal) continue;

tests/analysis/switch.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ const switch_tagged_union = switch (some_tagged_union) {
4040
.bar => |a| a,
4141
// ^ (bool)()
4242
else => |a| a,
43-
// ^ (unknown)() TODO this should be `TaggedUnion`
43+
// ^ (TaggedUnion)()
4444
};
4545

4646
const switch_null = switch (null) {

0 commit comments

Comments
 (0)