File tree Expand file tree Collapse file tree 2 files changed +31
-1
lines changed Expand file tree Collapse file tree 2 files changed +31
-1
lines changed Original file line number Diff line number Diff line change @@ -1710,8 +1710,17 @@ FunctionType *ConstraintSystem::adjustFunctionTypeForConcurrency(
1710
1710
});
1711
1711
1712
1712
if (Context.LangOpts .hasFeature (Feature::InferSendableFromCaptures)) {
1713
+ DeclContext *DC = nullptr ;
1713
1714
if (auto *FD = dyn_cast<AbstractFunctionDecl>(decl)) {
1714
- auto *DC = FD->getDeclContext ();
1715
+ DC = FD->getDeclContext ();
1716
+ } else if (auto EED = dyn_cast<EnumElementDecl>(decl)) {
1717
+ if (EED->hasAssociatedValues () &&
1718
+ !locator.endsWith <LocatorPathElt::PatternMatch>()) {
1719
+ DC = EED->getDeclContext ();
1720
+ }
1721
+ }
1722
+
1723
+ if (DC) {
1715
1724
// All global functions should be @Sendable
1716
1725
if (DC->isModuleScopeContext ()) {
1717
1726
if (!adjustedTy->getExtInfo ().isSendable ()) {
Original file line number Diff line number Diff line change @@ -42,6 +42,7 @@ struct InferredSendableS: P {
42
42
43
43
enum InferredSendableE : P {
44
44
case a, b
45
+ case c( Int )
45
46
46
47
func f( ) { }
47
48
}
@@ -60,6 +61,13 @@ struct GenericS<T> : P {
60
61
func g( ) async { }
61
62
}
62
63
64
+ enum GenericE < T> {
65
+ case a
66
+ case b( T )
67
+ }
68
+
69
+ extension GenericE : Sendable where T: Sendable { }
70
+
63
71
class NonSendable {
64
72
func f( ) { }
65
73
}
@@ -265,3 +273,16 @@ do {
265
273
true ? nil : c // Ok
266
274
}
267
275
}
276
+
277
+ func acceptSendableFunc< T, U> ( _: @Sendable ( T ) -> U ) { }
278
+
279
+ acceptSendableFunc ( InferredSendableE . c)
280
+ acceptSendableFunc ( GenericE< Int> . b)
281
+ acceptSendableFunc ( GenericE< NonSendable> . b)
282
+
283
+ // Make sure pattern matching isn't affected by @Sendable on cases.
284
+ func testPatternMatch( ge: [ GenericE < Int > ] ) {
285
+ if case . b( let a) = ge. first {
286
+ _ = a
287
+ }
288
+ }
You can’t perform that action at this time.
0 commit comments