[ConstaintSystem] Adjust getEffectiveOverloadType to ignore Optional.init

This commit is contained in:
Pavel Yaskevich
2019-07-23 14:46:20 -07:00
parent 44f82f256f
commit 654c1ae219

View File

@@ -1494,10 +1494,18 @@ Type ConstraintSystem::getEffectiveOverloadType(const OverloadChoice &overload,
return Type();
if (!overload.getBaseType()->getOptionalObjectType()) {
Type selfType = overload.getBaseType()->getRValueType()
->getMetatypeInstanceType()
->lookThroughAllOptionalTypes();
type = type->replaceCovariantResultType(selfType, 2);
Type selfType = overload.getBaseType()
->getRValueType()
->getMetatypeInstanceType();
// `Int??(0)` if we look through all optional types for `Self`
// we'll end up with incorrect type `Int?` for result because
// the actual result type is `Int??`.
if (isa<ConstructorDecl>(decl) && selfType->getOptionalObjectType())
return Type();
type = type->replaceCovariantResultType(
selfType->lookThroughAllOptionalTypes(), 2);
}
}
}