-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[Concurrency] Disallow Sendable annotation on methods of non-Sendable types #69177
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
[Concurrency] Disallow Sendable annotation on methods of non-Sendable types #69177
Conversation
@swift-ci please smoke test |
lib/Sema/TypeCheckAttr.cpp
Outdated
// Prevent Sendable Attr from being added to methods of non-sendable types | ||
if (auto *funcDecl = dyn_cast<AbstractFunctionDecl>(D)) { | ||
if (auto baseType = funcDecl->getImplicitSelfDecl()->getTypeInContext()) { | ||
if (!isSendableType(dc->getParentModule(), baseType)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does this behave for conditional conformances? e.g.
struct S<T> {
let t: T
@Sendable func test() {}
}
extension S: Sendable where T: Sendable {
@Sendable func test2() {}
}
It seems like the first @Sendable
should be diagnosed but the second should not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should work out. isSendableType()
calls TypeChecker::conformsToProtocol()
which checks conditional requirements, and getSelfTypeInContext()
maps the interface type of self
into the function's own generic environment, so the generic parameters become archetypes that satisfy those conditional requirements. Worth adding a test though!
bfeed03
to
11aaebc
Compare
@swift-ci please smoke test |
0efd4df
to
558b5dd
Compare
558b5dd
to
e779b05
Compare
@swift-ci please smoke test |
Disallow Sendable annotation on methods of non-Sendable types.