@@ -896,6 +896,48 @@ namespace {
896896 return closedAny;
897897 }
898898
899+ // / When we have a reference to a declaration whose type in context is
900+ // / different from its normal interface type, introduce the appropriate
901+ // / conversions. This can happen due to `@preconcurrency`.
902+ Expr *adjustTypeForDeclReference (
903+ Expr *expr, Type openedType, Type adjustedOpenedType,
904+ llvm::function_ref<Type(Type)> getNewType = [](Type type) {
905+ return type;
906+ }) {
907+ // If the types are the same, do nothing.
908+ if (openedType->isEqual (adjustedOpenedType))
909+ return expr;
910+
911+ auto &context = cs.getASTContext ();
912+
913+ // If we have an optional type, wrap it up in a monadic '?' and recurse.
914+ if (Type objectType = openedType->getOptionalObjectType ()) {
915+ Type adjustedRefType = getNewType (adjustedOpenedType);
916+ Type adjustedObjectType = adjustedRefType->getOptionalObjectType ();
917+ assert (adjustedObjectType && " Not an optional?" );
918+
919+ expr = new (context) BindOptionalExpr (expr, SourceLoc (), 0 , objectType);
920+ cs.cacheType (expr);
921+ expr = adjustTypeForDeclReference (expr, objectType, adjustedObjectType);
922+ expr = new (context) InjectIntoOptionalExpr (expr, adjustedRefType);
923+ cs.cacheType (expr);
924+ expr = new (context) OptionalEvaluationExpr (expr, adjustedRefType);
925+ cs.cacheType (expr);
926+ return expr;
927+ }
928+
929+ // For a function type, perform a function conversion.
930+ if (openedType->is <AnyFunctionType>()) {
931+ expr = new (context) FunctionConversionExpr (
932+ expr, getNewType (adjustedOpenedType));
933+ cs.cacheType (expr);
934+ return expr;
935+ }
936+
937+ assert (false && " Unhandled adjustment" );
938+ return expr;
939+ }
940+
899941 // / Determines if a partially-applied member reference should be
900942 // / converted into a fully-applied member reference with a pair of
901943 // / closures.
@@ -1388,6 +1430,7 @@ namespace {
13881430 ConstraintLocatorBuilder memberLocator, bool Implicit,
13891431 AccessSemantics semantics) {
13901432 const auto &choice = overload.choice ;
1433+ const auto openedType = overload.openedType ;
13911434 const auto adjustedOpenedType = overload.adjustedOpenedType ;
13921435
13931436 ValueDecl *member = choice.getDecl ();
@@ -1597,7 +1640,7 @@ namespace {
15971640
15981641 auto computeRefType = [&](Type openedType) {
15991642 // Compute the type of the reference.
1600- Type refType = simplifyType (adjustedOpenedType );
1643+ Type refType = simplifyType (openedType );
16011644
16021645 // If the base was an opened existential, erase the opened
16031646 // existential.
@@ -1609,9 +1652,13 @@ namespace {
16091652 return refType;
16101653 };
16111654
1612- Type refType = computeRefType (adjustedOpenedType );
1655+ Type refType = computeRefType (openedType );
16131656 cs.setType (ref, refType);
16141657
1658+ // Adjust the declaration reference type, if required.
1659+ ref = adjustTypeForDeclReference (
1660+ ref, openedType, adjustedOpenedType, computeRefType);
1661+
16151662 closeExistentials (ref, locator, /* force=*/ openedExistential);
16161663
16171664 // We also need to handle the implicitly unwrap of the result
0 commit comments