@@ -13210,18 +13210,14 @@ bool ConstraintSystem::simplifyAppliedOverloadsImpl(
13210
13210
13211
13211
/// The common result type amongst all function overloads.
13212
13212
Type commonResultType;
13213
- auto updateCommonResultType = [&](Type choiceType) {
13214
- auto markFailure = [&] {
13215
- commonResultType = ErrorType::get(getASTContext());
13216
- };
13217
13213
13218
- auto choiceFnType = choiceType->getAs<FunctionType>();
13219
- if (!choiceFnType)
13220
- return markFailure() ;
13214
+ auto markFailure = [&] {
13215
+ commonResultType = ErrorType::get(getASTContext());
13216
+ } ;
13221
13217
13218
+ auto updateCommonResultType = [&](Type choiceResultType) {
13222
13219
// For now, don't attempt to establish a common result type when there
13223
13220
// are type parameters.
13224
- Type choiceResultType = choiceFnType->getResult();
13225
13221
if (choiceResultType->hasTypeParameter())
13226
13222
return markFailure();
13227
13223
@@ -13359,8 +13355,28 @@ bool ConstraintSystem::simplifyAppliedOverloadsImpl(
13359
13355
choiceType = objectType;
13360
13356
}
13361
13357
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
+
13364
13380
return true;
13365
13381
});
13366
13382
0 commit comments