authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-06-26 12:31:51-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-06-26 12:31:51-04:00
logff737cc6483e29b2b8c5af1b7c8ed17bb6c70f32
treec4d0807fcc7199c84d413849b02cd5bffc806072
parentb4e40cb59a4d8ee498a0ae5b892bb5907745dc1e
signaturelock-open Commit is signed but in an unrecognized format.

fix peer type resolution: unreachable, error set, unreachable


3 files changed, 41 insertions(+), 7 deletions(-)

src/ir.cpp+17-5
......@@ -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+1-2
......@@ -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+23
......@@ -496,3 +496,26 @@ test "peer type resolution: unreachable, null, slice" {
496496 };
497497 S.doTheTest(1, "hi");
498498}
499
500test "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}