Skip to content

Commit aa75aad

Browse files
committed
[Sema]Set isAsync only when it is in async context
1 parent 7365d09 commit aa75aad

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

lib/Sema/CSApply.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8217,6 +8217,16 @@ Expr *ExprRewriter::finishApply(ApplyExpr *apply, Type openedType,
82178217
// Resolve into a MakeTemporarilyEscapableExpr.
82188218
auto *args = apply->getArgs();
82198219
assert(args->size() == 2 && "should have two arguments");
8220+
auto appliedWrappers =
8221+
solution.getAppliedPropertyWrappers(calleeLocator.getAnchor());
8222+
auto fnType = cs.getType(fn)->getAs<FunctionType>();
8223+
args = coerceCallArguments(
8224+
args, fnType, declRef, apply,
8225+
locator.withPathElement(ConstraintLocator::ApplyArgument),
8226+
appliedWrappers);
8227+
if (!args)
8228+
return nullptr;
8229+
82208230
auto *nonescaping = cs.coerceToRValue(args->getExpr(0));
82218231
auto *body = args->getExpr(1);
82228232
auto bodyTy = cs.getType(body)->getWithoutSpecifierType();

lib/Sema/TypeOfReference.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2214,7 +2214,7 @@ isInvalidPartialApplication(ConstraintSystem &cs,
22142214
/// the full opened type and the reference's type.
22152215
static DeclReferenceType getTypeOfReferenceWithSpecialTypeCheckingSemantics(
22162216
ConstraintSystem &CS, ConstraintLocator *locator,
2217-
DeclTypeCheckingSemantics semantics) {
2217+
DeclTypeCheckingSemantics semantics, DeclContext *useDC) {
22182218
switch (semantics) {
22192219
case DeclTypeCheckingSemantics::Normal:
22202220
llvm_unreachable("Decl does not have special type checking semantics!");
@@ -2261,10 +2261,11 @@ static DeclReferenceType getTypeOfReferenceWithSpecialTypeCheckingSemantics(
22612261
CS.getConstraintLocator(locator, ConstraintLocator::ThrownErrorType),
22622262
0);
22632263
FunctionType::Param arg(escapeClosure);
2264+
bool isAsync = CS.isAsynchronousContext(useDC);
22642265
auto bodyClosure = FunctionType::get(arg, result,
22652266
FunctionType::ExtInfoBuilder()
22662267
.withNoEscape(true)
2267-
.withAsync(true)
2268+
.withAsync(isAsync)
22682269
.withThrows(true, thrownError)
22692270
.build());
22702271
FunctionType::Param args[] = {
@@ -2275,7 +2276,7 @@ static DeclReferenceType getTypeOfReferenceWithSpecialTypeCheckingSemantics(
22752276
auto refType = FunctionType::get(args, result,
22762277
FunctionType::ExtInfoBuilder()
22772278
.withNoEscape(false)
2278-
.withAsync(true)
2279+
.withAsync(isAsync)
22792280
.withThrows(true, thrownError)
22802281
.build());
22812282
return {refType, refType, refType, refType, Type()};
@@ -2370,7 +2371,7 @@ void ConstraintSystem::resolveOverload(ConstraintLocator *locator,
23702371
DeclReferenceType declRefType;
23712372
if (semantics != DeclTypeCheckingSemantics::Normal) {
23722373
declRefType = getTypeOfReferenceWithSpecialTypeCheckingSemantics(
2373-
*this, locator, semantics);
2374+
*this, locator, semantics, useDC);
23742375
} else if (auto baseTy = choice.getBaseType()) {
23752376
// Retrieve the type of a reference to the specific declaration choice.
23762377
assert(!baseTy->hasTypeParameter());

0 commit comments

Comments
 (0)