add peer type resolution for T and ?T

See #334
This commit is contained in:
Andrew Kelley 2017-04-22 11:45:04 -04:00
parent e0b635e825
commit 1a0081b763
2 changed files with 21 additions and 1 deletions

View File

@ -6120,6 +6120,15 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
{
prev_inst = cur_inst;
continue;
} else if (prev_type->id == TypeTableEntryIdMaybe &&
types_match_const_cast_only(prev_type->data.maybe.child_type, cur_type))
{
continue;
} else if (cur_type->id == TypeTableEntryIdMaybe &&
types_match_const_cast_only(cur_type->data.maybe.child_type, prev_type))
{
prev_inst = cur_inst;
continue;
} else if (prev_type->id == TypeTableEntryIdNumLitInt ||
prev_type->id == TypeTableEntryIdNumLitFloat)
{

View File

@ -116,4 +116,15 @@ fn returnNullFromMaybeTypeErrorRef() -> %?&A {
}
fn returnNullLitFromMaybeTypeErrorRef() -> %?&A {
return null;
}
}
test "peer type resolution: ?T and T" {
assert(??peerTypeTAndMaybeT(true, false) == 0);
}
fn peerTypeTAndMaybeT(c: bool, b: bool) -> ?usize {
if (c) {
return if (b) null else usize(0);
}
return usize(3);
}