Skip to content

Commit 654c1ae

Browse files
committed
[ConstaintSystem] Adjust getEffectiveOverloadType to ignore Optional.init
1 parent 44f82f2 commit 654c1ae

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

lib/Sema/ConstraintSystem.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1494,10 +1494,18 @@ Type ConstraintSystem::getEffectiveOverloadType(const OverloadChoice &overload,
14941494
return Type();
14951495

14961496
if (!overload.getBaseType()->getOptionalObjectType()) {
1497-
Type selfType = overload.getBaseType()->getRValueType()
1498-
->getMetatypeInstanceType()
1499-
->lookThroughAllOptionalTypes();
1500-
type = type->replaceCovariantResultType(selfType, 2);
1497+
Type selfType = overload.getBaseType()
1498+
->getRValueType()
1499+
->getMetatypeInstanceType();
1500+
1501+
// `Int??(0)` if we look through all optional types for `Self`
1502+
// we'll end up with incorrect type `Int?` for result because
1503+
// the actual result type is `Int??`.
1504+
if (isa<ConstructorDecl>(decl) && selfType->getOptionalObjectType())
1505+
return Type();
1506+
1507+
type = type->replaceCovariantResultType(
1508+
selfType->lookThroughAllOptionalTypes(), 2);
15011509
}
15021510
}
15031511
}

0 commit comments

Comments
 (0)