@@ -1388,7 +1388,7 @@ namespace {
13881388 ConstraintLocatorBuilder memberLocator, bool Implicit,
13891389 AccessSemantics semantics) {
13901390 const auto &choice = overload.choice ;
1391- const auto adjustedOpenedType = overload.openedType ;
1391+ const auto adjustedOpenedType = overload.adjustedOpenedType ;
13921392
13931393 ValueDecl *member = choice.getDecl ();
13941394
@@ -1595,16 +1595,21 @@ namespace {
15951595 ref->setImplicit (Implicit);
15961596 // FIXME: FunctionRefKind
15971597
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);
16001601
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+ };
16071611
1612+ Type refType = computeRefType (adjustedOpenedType);
16081613 cs.setType (ref, refType);
16091614
16101615 closeExistentials (ref, locator, /* force=*/ openedExistential);
@@ -1967,7 +1972,7 @@ namespace {
19671972 // Apply a key path if we have one.
19681973 if (choice.getKind () == OverloadChoiceKind::KeyPathApplication) {
19691974 auto applicationTy =
1970- simplifyType (selected.openedType )->castTo <FunctionType>();
1975+ simplifyType (selected.adjustedOpenedType )->castTo <FunctionType>();
19711976
19721977 // The index argument should be (keyPath: KeyPath<Root, Value>).
19731978 // Dig the key path expression out of the arguments.
@@ -2095,7 +2100,7 @@ namespace {
20952100 // TODO: diagnose if semantics != AccessSemantics::Ordinary?
20962101 auto subscriptExpr = DynamicSubscriptExpr::create (
20972102 ctx, base, args, subscriptRef, isImplicit);
2098- auto resultTy = simplifyType (selected.openedType )
2103+ auto resultTy = simplifyType (selected.adjustedOpenedType )
20992104 ->castTo <FunctionType>()
21002105 ->getResult ();
21012106 assert (!selected.adjustedOpenedFullType ->hasOpenedExistential ()
@@ -2152,7 +2157,7 @@ namespace {
21522157 // base object type.
21532158 if (hasDynamicSelf) {
21542159 const auto conversionTy = simplifyType (
2155- selected.openedType ->castTo <FunctionType>()->getResult ());
2160+ selected.adjustedOpenedType ->castTo <FunctionType>()->getResult ());
21562161
21572162 if (!containerTy->isEqual (conversionTy)) {
21582163 result = cs.cacheType (
@@ -2852,7 +2857,7 @@ namespace {
28522857 return nullptr ;
28532858
28542859 auto fnType =
2855- simplifyType (selectedOverload->openedType )->castTo <FunctionType>();
2860+ simplifyType (selectedOverload->adjustedOpenedType )->castTo <FunctionType>();
28562861
28572862 auto newArgs = coerceCallArguments (
28582863 expr->getArgs (), fnType, witness, /* applyExpr=*/ nullptr ,
@@ -5027,7 +5032,7 @@ namespace {
50275032 const SelectedOverload &overload, SourceLoc componentLoc,
50285033 ConstraintLocator *locator,
50295034 SmallVectorImpl<KeyPathExpr::Component> &components) {
5030- auto resolvedTy = simplifyType (overload.openedType );
5035+ auto resolvedTy = simplifyType (overload.adjustedOpenedType );
50315036 if (auto *property = overload.choice .getDeclOrNull ()) {
50325037 // Key paths can only refer to properties currently.
50335038 auto varDecl = cast<VarDecl>(property);
@@ -5088,7 +5093,7 @@ namespace {
50885093 }
50895094
50905095 auto subscriptType =
5091- simplifyType (overload.openedType )->castTo <AnyFunctionType>();
5096+ simplifyType (overload.adjustedOpenedType )->castTo <AnyFunctionType>();
50925097 auto resolvedTy = subscriptType->getResult ();
50935098
50945099 // Coerce the indices to the type the subscript expects.
@@ -5104,7 +5109,7 @@ namespace {
51045109
51055110 auto hashable = ctx.getProtocol (KnownProtocolKind::Hashable);
51065111
5107- auto fnType = overload.openedType ->castTo <FunctionType>();
5112+ auto fnType = overload.adjustedOpenedType ->castTo <FunctionType>();
51085113 SmallVector<Identifier, 4 > newLabels;
51095114 for (auto ¶m : fnType->getParams ()) {
51105115 newLabels.push_back (param.getLabel ());
@@ -7664,7 +7669,7 @@ Expr *ExprRewriter::finishApply(ApplyExpr *apply, Type openedType,
76647669 cs.getConstraintLocator (applyFunctionLoc))) {
76657670 auto *method = dyn_cast<FuncDecl>(selected->choice .getDecl ());
76667671 auto methodType =
7667- simplifyType (selected->openedType )->getAs <AnyFunctionType>();
7672+ simplifyType (selected->adjustedOpenedType )->getAs <AnyFunctionType>();
76687673 if (method && methodType) {
76697674 // Handle a call to a @dynamicCallable method.
76707675 if (isValidDynamicCallableMethod (method, methodType))
0 commit comments