Skip to content

Commit 5a8d259

Browse files
Resolve type of else capture in tagged union switch
1 parent 49e4a0e commit 5a8d259

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
@@ -5478,6 +5478,14 @@ pub const DeclWithHandle = struct {
54785478
if (switch_expr_type.isEnumType()) break :blk switch_expr_type;
54795479
if (!switch_expr_type.isUnionType()) return switch_expr_type;
54805480

5481+
if (case.ast.values.len == 0) {
5482+
if (case.inline_token == null) {
5483+
return switch_expr_type;
5484+
}
5485+
// TODO either type
5486+
return null;
5487+
}
5488+
54815489
// TODO Peer type resolution, we just use the first resolvable item for now.
54825490
for (case.ast.values) |case_value| {
54835491
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)