Skip to content

Commit a6548a8

Browse files
committed
Check if the type contains 'inout' anywhere in its description
This works regardless of SwiftSyntax version and handles cases like "isolated inout"
1 parent bd496c0 commit a6548a8

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

Sources/SpyableMacro/Factories/ClosureFactory.swift

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -203,16 +203,9 @@ struct ClosureFactory {
203203

204204
extension FunctionParameterListSyntax.Element {
205205
fileprivate var isInoutParameter: Bool {
206-
guard let attributedType = self.type.as(AttributedTypeSyntax.self) else {
207-
return false
208-
}
209-
210-
#if canImport(SwiftSyntax600)
211-
let specifier = attributedType.specifiers.first?.firstToken(viewMode: .all)?.text
212-
#else
213-
let specifier = attributedType.specifier?.text
214-
#endif
215-
216-
return specifier == TokenSyntax.keyword(.inout).text
206+
// Check if the type contains 'inout' anywhere in its description
207+
// This works regardless of SwiftSyntax version and handles cases like "isolated inout"
208+
let typeDescription = self.type.description.trimmingCharacters(in: .whitespacesAndNewlines)
209+
return typeDescription.contains("inout")
217210
}
218211
}

Tests/SpyableMacroTests/Factories/UT_ClosureFactory.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,14 @@ final class UT_ClosureFactory: XCTestCase {
5555
)
5656
}
5757

58+
func testVariableDeclarationWithIsolatedInoutAttribute() throws {
59+
try assertProtocolFunction(
60+
withFunctionDeclaration: "func _ignore_(value: isolated inout TestActor)",
61+
prefixForVariable: "_prefix_",
62+
expectingVariableDeclaration: "var _prefix_Closure: ((isolated inout TestActor) -> Void)?"
63+
)
64+
}
65+
5866
func testVariableDeclarationWithGenericParameter() throws {
5967
try assertProtocolFunction(
6068
withFunctionDeclaration: "func _ignore_<T>(value: T)",
@@ -133,6 +141,14 @@ final class UT_ClosureFactory: XCTestCase {
133141
)
134142
}
135143

144+
func testCallExpressionWithIsolatedInoutAttribute() throws {
145+
try assertProtocolFunction(
146+
withFunctionDeclaration: "func _ignore_(value: isolated inout TestActor)",
147+
prefixForVariable: "_prefix_",
148+
expectingCallExpression: "_prefix_Closure?(&value)"
149+
)
150+
}
151+
136152
func testCallExpressionWithGenericParameter() throws {
137153
try assertProtocolFunction(
138154
withFunctionDeclaration: "func _ignore_<T>(value: T)",

0 commit comments

Comments
 (0)