@@ -13210,18 +13210,14 @@ bool ConstraintSystem::simplifyAppliedOverloadsImpl(
1321013210
1321113211 /// The common result type amongst all function overloads.
1321213212 Type commonResultType;
13213- auto updateCommonResultType = [&](Type choiceType) {
13214- auto markFailure = [&] {
13215- commonResultType = ErrorType::get(getASTContext());
13216- };
1321713213
13218- auto choiceFnType = choiceType->getAs<FunctionType>();
13219- if (!choiceFnType)
13220- return markFailure() ;
13214+ auto markFailure = [&] {
13215+ commonResultType = ErrorType::get(getASTContext());
13216+ } ;
1322113217
13218+ auto updateCommonResultType = [&](Type choiceResultType) {
1322213219 // For now, don't attempt to establish a common result type when there
1322313220 // are type parameters.
13224- Type choiceResultType = choiceFnType->getResult();
1322513221 if (choiceResultType->hasTypeParameter())
1322613222 return markFailure();
1322713223
@@ -13359,8 +13355,28 @@ bool ConstraintSystem::simplifyAppliedOverloadsImpl(
1335913355 choiceType = objectType;
1336013356 }
1336113357
13362- // If we have a function type, we can compute a common result type.
13363- updateCommonResultType(choiceType);
13358+ if (auto *choiceFnType = choiceType->getAs<FunctionType>()) {
13359+ if (isa<ConstructorDecl>(choice.getDecl())) {
13360+ auto choiceResultType = choice.getBaseType()
13361+ ->getRValueType()
13362+ ->getMetatypeInstanceType();
13363+
13364+ if (choiceResultType->getOptionalObjectType()) {
13365+ hasUnhandledConstraints = true;
13366+ return true;
13367+ }
13368+
13369+ if (choiceFnType->getResult()->getOptionalObjectType())
13370+ choiceResultType = OptionalType::get(choiceResultType);
13371+
13372+ updateCommonResultType(choiceResultType);
13373+ } else {
13374+ updateCommonResultType(choiceFnType->getResult());
13375+ }
13376+ } else {
13377+ markFailure();
13378+ }
13379+
1336413380 return true;
1336513381 });
1336613382
0 commit comments