@@ -1388,7 +1388,7 @@ namespace {
1388
1388
ConstraintLocatorBuilder memberLocator, bool Implicit,
1389
1389
AccessSemantics semantics) {
1390
1390
const auto &choice = overload.choice ;
1391
- const auto adjustedOpenedType = overload.openedType ;
1391
+ const auto adjustedOpenedType = overload.adjustedOpenedType ;
1392
1392
1393
1393
ValueDecl *member = choice.getDecl ();
1394
1394
@@ -1595,16 +1595,21 @@ namespace {
1595
1595
ref->setImplicit (Implicit);
1596
1596
// FIXME: FunctionRefKind
1597
1597
1598
- // Compute the type of the reference.
1599
- Type refType = simplifyType (adjustedOpenedType);
1598
+ auto computeRefType = [&](Type openedType) {
1599
+ // Compute the type of the reference.
1600
+ Type refType = simplifyType (adjustedOpenedType);
1600
1601
1601
- // If the base was an opened existential, erase the opened
1602
- // existential.
1603
- if (openedExistential) {
1604
- refType = refType->typeEraseOpenedArchetypesWithRoot (
1605
- baseTy->castTo <OpenedArchetypeType>(), dc);
1606
- }
1602
+ // If the base was an opened existential, erase the opened
1603
+ // existential.
1604
+ if (openedExistential) {
1605
+ refType = refType->typeEraseOpenedArchetypesWithRoot (
1606
+ baseTy->castTo <OpenedArchetypeType>(), dc);
1607
+ }
1608
+
1609
+ return refType;
1610
+ };
1607
1611
1612
+ Type refType = computeRefType (adjustedOpenedType);
1608
1613
cs.setType (ref, refType);
1609
1614
1610
1615
closeExistentials (ref, locator, /* force=*/ openedExistential);
@@ -1967,7 +1972,7 @@ namespace {
1967
1972
// Apply a key path if we have one.
1968
1973
if (choice.getKind () == OverloadChoiceKind::KeyPathApplication) {
1969
1974
auto applicationTy =
1970
- simplifyType (selected.openedType )->castTo <FunctionType>();
1975
+ simplifyType (selected.adjustedOpenedType )->castTo <FunctionType>();
1971
1976
1972
1977
// The index argument should be (keyPath: KeyPath<Root, Value>).
1973
1978
// Dig the key path expression out of the arguments.
@@ -2095,7 +2100,7 @@ namespace {
2095
2100
// TODO: diagnose if semantics != AccessSemantics::Ordinary?
2096
2101
auto subscriptExpr = DynamicSubscriptExpr::create (
2097
2102
ctx, base, args, subscriptRef, isImplicit);
2098
- auto resultTy = simplifyType (selected.openedType )
2103
+ auto resultTy = simplifyType (selected.adjustedOpenedType )
2099
2104
->castTo <FunctionType>()
2100
2105
->getResult ();
2101
2106
assert (!selected.adjustedOpenedFullType ->hasOpenedExistential ()
@@ -2152,7 +2157,7 @@ namespace {
2152
2157
// base object type.
2153
2158
if (hasDynamicSelf) {
2154
2159
const auto conversionTy = simplifyType (
2155
- selected.openedType ->castTo <FunctionType>()->getResult ());
2160
+ selected.adjustedOpenedType ->castTo <FunctionType>()->getResult ());
2156
2161
2157
2162
if (!containerTy->isEqual (conversionTy)) {
2158
2163
result = cs.cacheType (
@@ -2852,7 +2857,7 @@ namespace {
2852
2857
return nullptr ;
2853
2858
2854
2859
auto fnType =
2855
- simplifyType (selectedOverload->openedType )->castTo <FunctionType>();
2860
+ simplifyType (selectedOverload->adjustedOpenedType )->castTo <FunctionType>();
2856
2861
2857
2862
auto newArgs = coerceCallArguments (
2858
2863
expr->getArgs (), fnType, witness, /* applyExpr=*/ nullptr ,
@@ -5027,7 +5032,7 @@ namespace {
5027
5032
const SelectedOverload &overload, SourceLoc componentLoc,
5028
5033
ConstraintLocator *locator,
5029
5034
SmallVectorImpl<KeyPathExpr::Component> &components) {
5030
- auto resolvedTy = simplifyType (overload.openedType );
5035
+ auto resolvedTy = simplifyType (overload.adjustedOpenedType );
5031
5036
if (auto *property = overload.choice .getDeclOrNull ()) {
5032
5037
// Key paths can only refer to properties currently.
5033
5038
auto varDecl = cast<VarDecl>(property);
@@ -5088,7 +5093,7 @@ namespace {
5088
5093
}
5089
5094
5090
5095
auto subscriptType =
5091
- simplifyType (overload.openedType )->castTo <AnyFunctionType>();
5096
+ simplifyType (overload.adjustedOpenedType )->castTo <AnyFunctionType>();
5092
5097
auto resolvedTy = subscriptType->getResult ();
5093
5098
5094
5099
// Coerce the indices to the type the subscript expects.
@@ -5104,7 +5109,7 @@ namespace {
5104
5109
5105
5110
auto hashable = ctx.getProtocol (KnownProtocolKind::Hashable);
5106
5111
5107
- auto fnType = overload.openedType ->castTo <FunctionType>();
5112
+ auto fnType = overload.adjustedOpenedType ->castTo <FunctionType>();
5108
5113
SmallVector<Identifier, 4 > newLabels;
5109
5114
for (auto ¶m : fnType->getParams ()) {
5110
5115
newLabels.push_back (param.getLabel ());
@@ -7664,7 +7669,7 @@ Expr *ExprRewriter::finishApply(ApplyExpr *apply, Type openedType,
7664
7669
cs.getConstraintLocator (applyFunctionLoc))) {
7665
7670
auto *method = dyn_cast<FuncDecl>(selected->choice .getDecl ());
7666
7671
auto methodType =
7667
- simplifyType (selected->openedType )->getAs <AnyFunctionType>();
7672
+ simplifyType (selected->adjustedOpenedType )->getAs <AnyFunctionType>();
7668
7673
if (method && methodType) {
7669
7674
// Handle a call to a @dynamicCallable method.
7670
7675
if (isValidDynamicCallableMethod (method, methodType))
0 commit comments