Skip to content

Commit 12ee623

Browse files
• Fix XCode 15.2 and SwiftSyntax issues
1 parent a37214d commit 12ee623

File tree

3 files changed

+20
-16
lines changed

3 files changed

+20
-16
lines changed

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ let package = Package(
2020
],
2121
dependencies: [
2222
// Depend on the latest Swift 5.9 prerelease of SwiftSyntax
23-
.package(url: "https://github.com/apple/swift-syntax.git", from: "509.0.0-swift-5.9-DEVELOPMENT-SNAPSHOT-2023-04-25-b"),
23+
.package(url: "https://github.com/apple/swift-syntax.git", from: "509.1.1"),
2424
],
2525
targets: [
2626
// Targets are the basic building blocks of a package, defining a module or a test suite.

Sources/ModifiedCopyMacros/ModifiedCopyMacro.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,17 @@ public struct ModifiedCopyMacro: MemberMacro {
4646
return []
4747
}
4848

49-
let structVisibility = structDeclSyntax.modifiers?.visibilityText() ?? "internal"
49+
let structVisibility = structDeclSyntax.modifiers.visibilityText() ?? "internal"
5050

5151
let variables = structDeclSyntax.memberBlock.members.compactMap { $0.decl.as(VariableDeclSyntax.self) }
5252

53-
let bindings = variables.flatMap(\.bindings).filter { accessorIsAllowed($0.accessor) }
53+
let bindings = variables.flatMap(\.bindings).filter { accessorIsAllowed($0.accessorBlock?.accessors) }
5454

5555
return variables.flatMap { variable in
56-
let variableVisibility = variable.modifiers?.visibilityText() ?? structVisibility
56+
let variableVisibility = variable.modifiers.visibilityText() ?? structVisibility
5757

5858
return variable.bindings
59-
.filter { accessorIsAllowed($0.accessor) }
59+
.filter { accessorIsAllowed($0.accessorBlock?.accessors) }
6060
.compactMap { binding -> DeclSyntax? in
6161
let propertyName = binding.pattern
6262
guard let typeName = binding.typeAnnotation?.type else {
@@ -75,20 +75,20 @@ public struct ModifiedCopyMacro: MemberMacro {
7575
}
7676
}
7777

78-
private static func accessorIsAllowed(_ accessor: PatternBindingSyntax.Accessor?) -> Bool {
78+
private static func accessorIsAllowed(_ accessor: AccessorBlockSyntax.Accessors?) -> Bool {
7979
guard let accessor else { return true }
8080
return switch accessor {
8181
case .accessors(let accessorDeclListSyntax):
82-
!accessorDeclListSyntax.accessors.contains {
83-
$0.accessorKind.text == "get" || $0.accessorKind.text == "set"
82+
!accessorDeclListSyntax.contains {
83+
$0.accessorSpecifier.text == "get" || $0.accessorSpecifier.text == "set"
8484
}
8585
case .getter:
8686
false
8787
}
8888
}
8989
}
9090

91-
extension ModifierListSyntax {
91+
extension DeclModifierListSyntax {
9292
private static let visibilityModifiers: Set = ["private", "fileprivate", "internal", "package", "public", "open"]
9393

9494
func visibilityText() -> String? {

Tests/ModifiedCopyTests/ModifiedCopyTests.swift

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ final class ModifiedCopyTests: XCTestCase {
4545
private(set) var name: String
4646
4747
let age: Int
48-
48+
4949
private var favoriteColor: String
5050
5151
/// This should not generate a copy function because it's not a stored property.
@@ -57,12 +57,12 @@ final class ModifiedCopyTests: XCTestCase {
5757
name = newValue
5858
}
5959
}
60-
60+
6161
/// This should not generate a copy function because it's not a stored property.
6262
var uppercasedName: String {
6363
name.uppercased()
6464
}
65-
65+
6666
var nickName: String? = "Bobby Tables" {
6767
didSet {
6868
print("nickName changed to \(nickName ?? "(nil)")")
@@ -80,12 +80,12 @@ final class ModifiedCopyTests: XCTestCase {
8080
expandedSource:
8181
#"""
8282
public struct Person {
83-
private (set) var name: String
84-
83+
private(set) var name: String
84+
8585
let age: Int
8686
8787
private var favoriteColor: String
88-
88+
8989
/// This should not generate a copy function because it's not a stored property.
9090
var fullName: String {
9191
get {
@@ -106,25 +106,29 @@ final class ModifiedCopyTests: XCTestCase {
106106
print("nickName changed to \(nickName ?? "(nil)")")
107107
}
108108
}
109-
109+
110110
init(name: String, age: Int, favoriteColor: String, nickName: String? = nil) {
111111
self.name = name
112112
self.age = age
113113
self.favoriteColor = favoriteColor
114114
self.nickName = nickName
115115
}
116+
116117
/// Returns a copy of the caller whose value for `name` is different.
117118
private func copy(name: String) -> Self {
118119
.init(name: name, age: age, favoriteColor: favoriteColor, nickName: nickName)
119120
}
121+
120122
/// Returns a copy of the caller whose value for `age` is different.
121123
public func copy(age: Int) -> Self {
122124
.init(name: name, age: age, favoriteColor: favoriteColor, nickName: nickName)
123125
}
126+
124127
/// Returns a copy of the caller whose value for `favoriteColor` is different.
125128
private func copy(favoriteColor: String) -> Self {
126129
.init(name: name, age: age, favoriteColor: favoriteColor, nickName: nickName)
127130
}
131+
128132
/// Returns a copy of the caller whose value for `nickName` is different.
129133
public func copy(nickName: String?) -> Self {
130134
.init(name: name, age: age, favoriteColor: favoriteColor, nickName: nickName)

0 commit comments

Comments
 (0)