Skip to content

Commit a37214d

Browse files
author
Wilhelm Oks
committed
fixed build and test errors for new Swift version in Xcode 15.0.1
1 parent 441751c commit a37214d

File tree

2 files changed

+26
-29
lines changed

2 files changed

+26
-29
lines changed

Sources/ModifiedCopyMacros/ModifiedCopyMacro.swift

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ enum ModifiedCopyDiagnostic: DiagnosticMessage {
2727
var diagnosticID: MessageID {
2828
switch self {
2929
case .notAStruct:
30-
.init(domain: "ModifiedCopyMacros", id: "notAStruct")
30+
.init(domain: "ModifiedCopyMacros", id: "notAStruct")
3131
case .propertyTypeProblem(let binding):
32-
.init(domain: "ModifiedCopyMacros", id: "propertyTypeProblem(\(binding.pattern))")
32+
.init(domain: "ModifiedCopyMacros", id: "propertyTypeProblem(\(binding.pattern))")
3333
}
3434
}
3535
}
@@ -41,26 +41,26 @@ public struct ModifiedCopyMacro: MemberMacro {
4141
in context: some MacroExpansionContext
4242
) throws -> [DeclSyntax] {
4343
guard let structDeclSyntax = declaration as? StructDeclSyntax else {
44-
let diagnostic = Diagnostic(node: node, message: ModifiedCopyDiagnostic.notAStruct
45-
)
44+
let diagnostic = Diagnostic(node: Syntax(node), message: ModifiedCopyDiagnostic.notAStruct)
4645
context.diagnose(diagnostic)
4746
return []
4847
}
49-
let structVisibility = structDeclSyntax.modifiers.visibilityText() ?? "internal"
48+
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.accessorBlock) }
53+
let bindings = variables.flatMap(\.bindings).filter { accessorIsAllowed($0.accessor) }
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.accessorBlock) }
59+
.filter { accessorIsAllowed($0.accessor) }
6060
.compactMap { binding -> DeclSyntax? in
6161
let propertyName = binding.pattern
6262
guard let typeName = binding.typeAnnotation?.type else {
63-
let diagnostic = Diagnostic(node: node, message: ModifiedCopyDiagnostic.propertyTypeProblem(binding))
63+
let diagnostic = Diagnostic(node: Syntax(node), message: ModifiedCopyDiagnostic.propertyTypeProblem(binding))
6464
context.diagnose(diagnostic)
6565
return nil
6666
}
@@ -75,20 +75,20 @@ public struct ModifiedCopyMacro: MemberMacro {
7575
}
7676
}
7777

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

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

9494
func visibilityText() -> String? {

Tests/ModifiedCopyTests/ModifiedCopyTests.swift

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,15 @@ final class ModifiedCopyTests: XCTestCase {
7777
}
7878
}
7979
"""#,
80-
expandedSource: #"""
80+
expandedSource:
81+
#"""
8182
public struct Person {
82-
private(set) var name: String
83-
83+
private (set) var name: String
84+
8485
let age: Int
85-
86+
8687
private var favoriteColor: String
87-
88+
8889
/// This should not generate a copy function because it's not a stored property.
8990
var fullName: String {
9091
get {
@@ -94,40 +95,36 @@ final class ModifiedCopyTests: XCTestCase {
9495
name = newValue
9596
}
9697
}
97-
98+
9899
/// This should not generate a copy function because it's not a stored property.
99100
var uppercasedName: String {
100101
name.uppercased()
101102
}
102-
103+
103104
var nickName: String? = "Bobby Tables" {
104105
didSet {
105106
print("nickName changed to \(nickName ?? "(nil)")")
106107
}
107108
}
108-
109+
109110
init(name: String, age: Int, favoriteColor: String, nickName: String? = nil) {
110111
self.name = name
111112
self.age = age
112113
self.favoriteColor = favoriteColor
113114
self.nickName = nickName
114115
}
115-
116116
/// Returns a copy of the caller whose value for `name` is different.
117117
private func copy(name: String) -> Self {
118118
.init(name: name, age: age, favoriteColor: favoriteColor, nickName: nickName)
119119
}
120-
121120
/// Returns a copy of the caller whose value for `age` is different.
122121
public func copy(age: Int) -> Self {
123122
.init(name: name, age: age, favoriteColor: favoriteColor, nickName: nickName)
124123
}
125-
126124
/// Returns a copy of the caller whose value for `favoriteColor` is different.
127125
private func copy(favoriteColor: String) -> Self {
128126
.init(name: name, age: age, favoriteColor: favoriteColor, nickName: nickName)
129127
}
130-
131128
/// Returns a copy of the caller whose value for `nickName` is different.
132129
public func copy(nickName: String?) -> Self {
133130
.init(name: name, age: age, favoriteColor: favoriteColor, nickName: nickName)

0 commit comments

Comments
 (0)