Skip to content

Commit ff737cc

Browse files
committed
fix peer type resolution: unreachable, error set, unreachable
1 parent b4e40cb commit ff737cc

File tree

3 files changed

+41
-7
lines changed

3 files changed

+41
-7
lines changed

src/ir.cpp

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10093,9 +10093,21 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
1009310093
{
1009410094
Error err;
1009510095
assert(instruction_count >= 1);
10096-
IrInstruction *prev_inst = instructions[0];
10097-
if (type_is_invalid(prev_inst->value.type)) {
10098-
return ira->codegen->builtin_types.entry_invalid;
10096+
IrInstruction *prev_inst;
10097+
size_t i = 0;
10098+
for (;;) {
10099+
prev_inst = instructions[i];
10100+
if (type_is_invalid(prev_inst->value.type)) {
10101+
return ira->codegen->builtin_types.entry_invalid;
10102+
}
10103+
if (prev_inst->value.type->id == ZigTypeIdUnreachable) {
10104+
i += 1;
10105+
if (i == instruction_count) {
10106+
return prev_inst->value.type;
10107+
}
10108+
continue;
10109+
}
10110+
break;
1009910111
}
1010010112
ErrorTableEntry **errors = nullptr;
1010110113
size_t errors_count = 0;
@@ -10120,7 +10132,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
1012010132

1012110133
bool any_are_null = (prev_inst->value.type->id == ZigTypeIdNull);
1012210134
bool convert_to_const_slice = false;
10123-
for (size_t i = 1; i < instruction_count; i += 1) {
10135+
for (; i < instruction_count; i += 1) {
1012410136
IrInstruction *cur_inst = instructions[i];
1012510137
ZigType *cur_type = cur_inst->value.type;
1012610138
ZigType *prev_type = prev_inst->value.type;
@@ -10139,7 +10151,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
1013910151
}
1014010152

1014110153
if (prev_type->id == ZigTypeIdErrorSet) {
10142-
assert(err_set_type != nullptr);
10154+
ir_assert(err_set_type != nullptr, prev_inst);
1014310155
if (cur_type->id == ZigTypeIdErrorSet) {
1014410156
if (type_is_global_error_set(err_set_type)) {
1014510157
continue;

std/event/fs.zig

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1290,10 +1290,9 @@ pub fn Watch(comptime V: type) type {
12901290
error.FileDescriptorAlreadyPresentInSet => unreachable,
12911291
error.OperationCausesCircularLoop => unreachable,
12921292
error.FileDescriptorNotRegistered => unreachable,
1293-
error.SystemResources => error.SystemResources,
1294-
error.UserResourceLimitReached => error.UserResourceLimitReached,
12951293
error.FileDescriptorIncompatibleWithEpoll => unreachable,
12961294
error.Unexpected => unreachable,
1295+
else => |e| e,
12971296
};
12981297
await (async channel.put(transformed_err) catch unreachable);
12991298
};

test/stage1/behavior/cast.zig

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,3 +496,26 @@ test "peer type resolution: unreachable, null, slice" {
496496
};
497497
S.doTheTest(1, "hi");
498498
}
499+
500+
test "peer type resolution: unreachable, error set, unreachable" {
501+
const Error = error {
502+
FileDescriptorAlreadyPresentInSet,
503+
OperationCausesCircularLoop,
504+
FileDescriptorNotRegistered,
505+
SystemResources,
506+
UserResourceLimitReached,
507+
FileDescriptorIncompatibleWithEpoll,
508+
Unexpected,
509+
};
510+
var err = Error.SystemResources;
511+
const transformed_err = switch (err) {
512+
error.FileDescriptorAlreadyPresentInSet => unreachable,
513+
error.OperationCausesCircularLoop => unreachable,
514+
error.FileDescriptorNotRegistered => unreachable,
515+
error.SystemResources => error.SystemResources,
516+
error.UserResourceLimitReached => error.UserResourceLimitReached,
517+
error.FileDescriptorIncompatibleWithEpoll => unreachable,
518+
error.Unexpected => unreachable,
519+
};
520+
expect(transformed_err == error.SystemResources);
521+
}

0 commit comments

Comments
 (0)