1717#include " OpenedExistentials.h"
1818#include " TypeChecker.h"
1919#include " swift/AST/ConformanceLookup.h"
20+ #include " swift/AST/Decl.h"
2021#include " swift/AST/ExistentialLayout.h"
2122#include " swift/AST/Expr.h"
2223#include " swift/AST/GenericSignature.h"
@@ -777,7 +778,7 @@ static std::optional<DisjunctionInfo> preserveFavoringOfUnlabeledUnaryArgument(
777778 SmallVector<Constraint *, 2 > favoredChoices;
778779 forEachDisjunctionChoice (
779780 cs, disjunction,
780- [&argumentType, &favoredChoices, &argument](
781+ [&cs, & argumentType, &favoredChoices, &argument](
781782 Constraint *choice, ValueDecl *decl, FunctionType *overloadType) {
782783 if (decl->getAttrs ().hasAttribute <DisfavoredOverloadAttr>())
783784 return ;
@@ -793,8 +794,15 @@ static std::optional<DisjunctionInfo> preserveFavoringOfUnlabeledUnaryArgument(
793794 (isa<LiteralExpr>(argument) || isa<BinaryExpr>(argument)))
794795 return ;
795796
796- if (argumentType->isEqual (param.getPlainType ()))
797+ if (argumentType->isEqual (param.getPlainType ())) {
798+ if (auto *func = dyn_cast<AbstractFunctionDecl>(decl)) {
799+ if (func->isAsyncContext () !=
800+ cs.isAsynchronousContext (choice->getDeclContext ()))
801+ return ;
802+ }
803+
797804 favoredChoices.push_back (choice);
805+ }
798806 });
799807
800808 return DisjunctionInfoBuilder (/* score=*/ favoredChoices.empty () ? 0 : 1 ,
0 commit comments