File tree Expand file tree Collapse file tree 2 files changed +22
-14
lines changed Expand file tree Collapse file tree 2 files changed +22
-14
lines changed Original file line number Diff line number Diff line change @@ -1796,20 +1796,7 @@ namespace {
1796
1796
}
1797
1797
1798
1798
bool isInAsynchronousContext () const {
1799
- auto dc = getDeclContext ();
1800
- if (auto func = dyn_cast<AbstractFunctionDecl>(dc)) {
1801
- return func->isAsyncContext ();
1802
- }
1803
-
1804
- if (auto closure = dyn_cast<AbstractClosureExpr>(dc)) {
1805
- if (auto type = closure->getType ()) {
1806
- if (auto fnType = type->getAs <AnyFunctionType>()) {
1807
- return fnType->isAsync ();
1808
- }
1809
- }
1810
- }
1811
-
1812
- return false ;
1799
+ return isAsynchronousContext (getDeclContext ());
1813
1800
}
1814
1801
1815
1802
enum class AsyncMarkingResult {
@@ -4282,3 +4269,19 @@ AnyFunctionType *swift::adjustFunctionTypeForConcurrency(
4282
4269
bool swift::completionContextUsesConcurrencyFeatures (const DeclContext *dc) {
4283
4270
return contextUsesConcurrencyFeatures (dc);
4284
4271
}
4272
+
4273
+ bool swift::isAsynchronousContext (const DeclContext *dc) {
4274
+ if (auto func = dyn_cast<AbstractFunctionDecl>(dc)) {
4275
+ return func->isAsyncContext ();
4276
+ }
4277
+
4278
+ if (auto closure = dyn_cast<AbstractClosureExpr>(dc)) {
4279
+ if (auto type = closure->getType ()) {
4280
+ if (auto fnType = type->getAs <AnyFunctionType>()) {
4281
+ return fnType->isAsync ();
4282
+ }
4283
+ }
4284
+ }
4285
+
4286
+ return false ;
4287
+ }
Original file line number Diff line number Diff line change @@ -328,6 +328,11 @@ bool isDispatchQueueOperationName(StringRef name);
328
328
// / \returns true if an error occurred.
329
329
bool checkSendableConformance (
330
330
ProtocolConformance *conformance, SendableCheck check);
331
+
332
+ // / Check whether the given declaration context is asynchronous e.g.
333
+ // / function or a closure declaration marked as `async`.
334
+ bool isAsynchronousContext (const DeclContext *dc);
335
+
331
336
} // end namespace swift
332
337
333
338
#endif /* SWIFT_SEMA_TYPECHECKCONCURRENCY_H */
You can’t perform that action at this time.
0 commit comments