Fix redundantSendable incorrectly removing Sendable from types inside public extension (#2423)

Co-authored-by: calda <1811727+calda@users.noreply.github.com>
This commit is contained in:
Copilot
2026-03-04 07:07:46 -08:00
committed by Cal Stephens
parent f098405c8e
commit 64bb14a2cd
2 changed files with 42 additions and 1 deletions
+9 -1
View File
@@ -21,8 +21,16 @@ public extension FormatRule {
switch typeDeclaration.visibility() {
case .public, .open:
return
case .internal, .package, .fileprivate, .private, nil:
case .internal, .package, .fileprivate, .private:
break
case nil:
// A type with no explicit access modifier inside a public extension is effectively public
let isInPublicExtension = typeDeclaration.parentDeclarations.last.map {
$0.keyword == "extension" && $0.visibility() == .public
} ?? false
if isInPublicExtension {
return
}
}
guard let sendableConformance = typeDeclaration.conformances.first(where: {
+33
View File
@@ -93,6 +93,39 @@ final class RedundantSendableTests: XCTestCase {
testFormatting(for: input, [output], rules: [.redundantSendable])
}
func testDoesNotRemoveSendableFromTypeInsidePublicExtension() {
let input = """
public struct OuterStruct {}
public extension OuterStruct {
struct InnerStruct: Sendable {}
enum InnerEnum: Sendable {}
}
"""
testFormatting(for: input, rules: [.redundantSendable])
}
func testRemovesSendableFromTypeInsideInternalExtension() {
let input = """
struct OuterStruct {}
extension OuterStruct {
struct InnerStruct: Sendable {}
}
"""
let output = """
struct OuterStruct {}
extension OuterStruct {
struct InnerStruct {}
}
"""
testFormatting(for: input, [output], rules: [.redundantSendable])
}
func testRemovesSendableFromPackageValueTypes() {
let input = """
package struct PackageStruct: Sendable {