File tree Expand file tree Collapse file tree 3 files changed +40
-2
lines changed Expand file tree Collapse file tree 3 files changed +40
-2
lines changed Original file line number Diff line number Diff line change @@ -5135,8 +5135,9 @@ bool swift::checkSendableConformance(
5135
5135
auto conformanceDecl = conformanceDC->getAsDecl ();
5136
5136
auto behavior = SendableCheckContext (conformanceDC, check)
5137
5137
.defaultDiagnosticBehavior ();
5138
- if (conformanceDC->getParentSourceFile () &&
5139
- conformanceDC->getParentSourceFile () != nominal->getParentSourceFile ()) {
5138
+ if (conformanceDC->getOutermostParentSourceFile () &&
5139
+ conformanceDC->getOutermostParentSourceFile () !=
5140
+ nominal->getOutermostParentSourceFile ()) {
5140
5141
conformanceDecl->diagnose (diag::concurrent_value_outside_source_file,
5141
5142
nominal)
5142
5143
.limitBehavior (behavior);
Original file line number Diff line number Diff line change @@ -2057,6 +2057,31 @@ extension RequiredDefaultInitMacro: MemberMacro {
2057
2057
}
2058
2058
}
2059
2059
2060
+ public struct SendableMacro : ExtensionMacro {
2061
+ public static func expansion(
2062
+ of node: AttributeSyntax ,
2063
+ attachedTo decl: some DeclGroupSyntax ,
2064
+ providingExtensionsOf type: some TypeSyntaxProtocol ,
2065
+ conformingTo protocols: [ TypeSyntax ] ,
2066
+ in context: some MacroExpansionContext
2067
+ ) throws -> [ ExtensionDeclSyntax ] {
2068
+ if protocols. isEmpty {
2069
+ return [ ]
2070
+ }
2071
+
2072
+ let decl : DeclSyntax =
2073
+ """
2074
+ extension \( type. trimmed) : Sendable {
2075
+ }
2076
+
2077
+ """
2078
+
2079
+ return [
2080
+ decl. cast ( ExtensionDeclSyntax . self)
2081
+ ]
2082
+ }
2083
+ }
2084
+
2060
2085
public struct FakeCodeItemMacro : DeclarationMacro , PeerMacro {
2061
2086
public static func expansion(
2062
2087
of node: some FreestandingMacroExpansionSyntax ,
Original file line number Diff line number Diff line change @@ -244,3 +244,15 @@ func testStringFoo(s: String) {
244
244
" Test " . printFoo ( )
245
245
s. printFoo ( )
246
246
}
247
+
248
+ @attached ( extension, conformances: Sendable)
249
+ macro AddSendable( ) = #externalMacro( module: " MacroDefinition " , type: " SendableMacro " )
250
+
251
+ @AddSendable
252
+ final class SendableClass {
253
+ }
254
+
255
+ // expected-warning@+2 {{non-final class 'InvalidSendableClass' cannot conform to 'Sendable'; use '@unchecked Sendable'}}
256
+ @AddSendable
257
+ class InvalidSendableClass {
258
+ }
You can’t perform that action at this time.
0 commit comments