Skip to content

Commit 9e3d0e0

Browse files
committed
Sema: Move weird ConstructorDecl hack from getEffectiveOverloadType() to simplifyAppliedOverloadsImpl()
1 parent d8bf4a9 commit 9e3d0e0

File tree

2 files changed

+28
-28
lines changed

2 files changed

+28
-28
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -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

lib/Sema/TypeOfReference.cpp

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2008,25 +2008,9 @@ Type ConstraintSystem::getEffectiveOverloadType(ConstraintLocator *locator,
20082008
return Type();
20092009
}
20102010

2011-
// Hack for constructors.
20122011
if (isa<ConstructorDecl>(decl) &&
2013-
!decl->getDeclContext()->getSelfProtocolDecl()) {
2014-
if (!overload.getBaseType())
2015-
return Type();
2016-
2017-
if (!overload.getBaseType()->getOptionalObjectType()) {
2018-
// `Int??(0)` if we look through all optional types for `Self`
2019-
// we'll end up with incorrect type `Int?` for result because
2020-
// the actual result type is `Int??`.
2021-
if (overload.getBaseType()
2022-
->getRValueType()
2023-
->getMetatypeInstanceType()
2024-
->getOptionalObjectType())
2025-
return Type();
2026-
2027-
type = type->replaceCovariantResultType(
2028-
getBaseObjectType(), /*uncurryLevel=*/2);
2029-
}
2012+
decl->getDeclContext()->getSelfClassDecl()) {
2013+
type = type->withCovariantResultType();
20302014
}
20312015

20322016
// Cope with 'Self' returns.

0 commit comments

Comments
 (0)