diff --git a/src/ir.cpp b/src/ir.cpp index 75c49dc53..941210d58 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -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) { diff --git a/test/cases/cast.zig b/test/cases/cast.zig index 9f0d5f330..74c2ab7b3 100644 --- a/test/cases/cast.zig +++ b/test/cases/cast.zig @@ -116,4 +116,15 @@ fn returnNullFromMaybeTypeErrorRef() -> %?&A { } fn returnNullLitFromMaybeTypeErrorRef() -> %?&A { return null; -} \ No newline at end of file +} + +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); +}