authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-07-12 23:04:00-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-07-13 00:08:21-07:00
log8fe63d504226d5b181e627361e997a160dee4908
tree5abc9cd60f4178ae82a2a39ab94708cb72a609d4
parent1cab40d7837c69fe6a77f76be9dc27026acd935e

stage2: peer type resolution with noreturn


1 files changed, 18 insertions(+), 1 deletions(-)

src-self-hosted/Module.zig+18-1
...@@ -3518,9 +3518,26 @@ fn makeIntType(self: *Module, scope: *Scope, signed: bool, bits: u16) !Type {...@@ -3518,9 +3518,26 @@ fn makeIntType(self: *Module, scope: *Scope, signed: bool, bits: u16) !Type {
3518fn resolvePeerTypes(self: *Module, scope: *Scope, instructions: []*Inst) !Type {3518fn resolvePeerTypes(self: *Module, scope: *Scope, instructions: []*Inst) !Type {
3519 if (instructions.len == 0)3519 if (instructions.len == 0)
3520 return Type.initTag(.noreturn);3520 return Type.initTag(.noreturn);
3521
3521 if (instructions.len == 1)3522 if (instructions.len == 1)
3522 return instructions[0].ty;3523 return instructions[0].ty;
3523 return self.fail(scope, instructions[0].src, "TODO peer type resolution", .{});3524
3525 var prev_inst = instructions[0];
3526 for (instructions[1..]) |next_inst| {
3527 if (next_inst.ty.eql(prev_inst.ty))
3528 continue;
3529 if (next_inst.ty.zigTypeTag() == .NoReturn)
3530 continue;
3531 if (prev_inst.ty.zigTypeTag() == .NoReturn) {
3532 prev_inst = next_inst;
3533 continue;
3534 }
3535
3536 // TODO error notes pointing out each type
3537 return self.fail(scope, next_inst.src, "incompatible types: '{}' and '{}'", .{ prev_inst.ty, next_inst.ty });
3538 }
3539
3540 return prev_inst.ty;
3524}3541}
35253542
3526fn coerce(self: *Module, scope: *Scope, dest_type: Type, inst: *Inst) !*Inst {3543fn coerce(self: *Module, scope: *Scope, dest_type: Type, inst: *Inst) !*Inst {