Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swift 6 concurrency check not complaining about Objc block property #77416

Open
brustolin opened this issue Nov 6, 2024 · 1 comment
Open
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels

Comments

@brustolin
Copy link

brustolin commented Nov 6, 2024

Description

I work on an ObjC framework which contains an Option class with a beforeSend property block callback like so (names changed for simplicity):

typedef Event *_Nullable (^ BeforeSendCallback)(Event *_Nonnull event);

@interface Option 
@property (nonatomic, copy) BeforeSendCallback beforeSend;
//... More properties
@end

The beforeSend callback can be called from any thread, and when we do call it from a thread other than the one the user used to create the option object, the app crashes with EXC_BREAKPOINT, if the user didn't mark the closure with @Sendable.

I would think that the compiler should complain about this in Swift 6 mode. Am I missing something?

Reproduction

This crashes in runtime when beforeSend is used in a background thread:

MySDK.start { option in
 option.beforeSend = { event in
     //process event
     return event
  }
}

This does not crashes in runtime:

MySDK.start { option in
 option.beforeSend = { @Sendable event in
     //process event
     return event
  }
}

Expected behavior

I would expected the compiler to complain about the missing @Sendable in the closure or any other error.

Environment

swift-driver version: 1.115 Apple Swift version 6.0.2 (swiftlang-6.0.2.1.2 clang-1600.0.26.4)
Target: arm64-apple-macosx15.0

Additional information

No response

@brustolin brustolin added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels labels Nov 6, 2024
@jamieQ
Copy link
Contributor

jamieQ commented Nov 6, 2024

i'm not entirely sure what the expected behavior is in this case, but you may find this section of the Swift 6 migration guide of interest. in particular, there are some annotations that can be applied to objc code to communicate the intended swift concurrency behaviors of an API.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels
Projects
None yet
Development

No branches or pull requests

2 participants