stage2: peer type resolution with noreturn

This commit is contained in:
Andrew Kelley 2020-07-12 23:04:00 -07:00
parent 1cab40d783
commit 8fe63d5042

View File

@ -3518,9 +3518,26 @@ fn makeIntType(self: *Module, scope: *Scope, signed: bool, bits: u16) !Type {
fn resolvePeerTypes(self: *Module, scope: *Scope, instructions: []*Inst) !Type {
if (instructions.len == 0)
return Type.initTag(.noreturn);
if (instructions.len == 1)
return instructions[0].ty;
return self.fail(scope, instructions[0].src, "TODO peer type resolution", .{});
var prev_inst = instructions[0];
for (instructions[1..]) |next_inst| {
if (next_inst.ty.eql(prev_inst.ty))
continue;
if (next_inst.ty.zigTypeTag() == .NoReturn)
continue;
if (prev_inst.ty.zigTypeTag() == .NoReturn) {
prev_inst = next_inst;
continue;
}
// TODO error notes pointing out each type
return self.fail(scope, next_inst.src, "incompatible types: '{}' and '{}'", .{ prev_inst.ty, next_inst.ty });
}
return prev_inst.ty;
}
fn coerce(self: *Module, scope: *Scope, dest_type: Type, inst: *Inst) !*Inst {