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 @@ -1747,8 +1747,17 @@ FunctionType *ConstraintSystem::adjustFunctionTypeForConcurrency(
17471747 });
17481748
17491749 if (Context.LangOpts .hasFeature (Feature::InferSendableFromCaptures)) {
1750+ DeclContext *DC = nullptr ;
17501751 if (auto *FD = dyn_cast<AbstractFunctionDecl>(decl)) {
1751- auto *DC = FD->getDeclContext ();
1752+ DC = FD->getDeclContext ();
1753+ } else if (auto EED = dyn_cast<EnumElementDecl>(decl)) {
1754+ if (EED->hasAssociatedValues () &&
1755+ !locator.endsWith <LocatorPathElt::PatternMatch>()) {
1756+ DC = EED->getDeclContext ();
1757+ }
1758+ }
1759+
1760+ if (DC) {
17521761 // All global functions should be @Sendable
17531762 if (DC->isModuleScopeContext ()) {
17541763 if (!adjustedTy->getExtInfo ().isSendable ()) {
Original file line number Diff line number Diff line change @@ -42,6 +42,7 @@ struct InferredSendableS: P {
4242
4343enum InferredSendableE : P {
4444 case a, b
45+ case c( Int )
4546
4647 func f( ) { }
4748}
@@ -60,6 +61,13 @@ struct GenericS<T> : P {
6061 func g( ) async { }
6162}
6263
64+ enum GenericE < T> {
65+ case a
66+ case b( T )
67+ }
68+
69+ extension GenericE : Sendable where T: Sendable { }
70+
6371class NonSendable {
6472 func f( ) { }
6573}
@@ -265,3 +273,16 @@ do {
265273 true ? nil : c // Ok
266274 }
267275}
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