Skip to content

Commit ed93fe6

Browse files
authored
Merge pull request #145 from ThomasDutartre/fix-warnings
2 parents 5ee55d3 + ca2c9ea commit ed93fe6

File tree

5 files changed

+62
-18
lines changed

5 files changed

+62
-18
lines changed

Sources/SpyableMacro/Extensions/TypeSyntax+Extensions.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,13 +131,17 @@ extension GenericArgumentClauseSyntax: TypeSyntaxSupportingGenerics {
131131
newArgument = type.erasingGenericTypes(genericTypes)
132132
default: continue
133133
}
134+
let newArgumentElement = GenericArgumentSyntax(
135+
argument: .type(newArgument),
136+
trailingComma: argumentElement.trailingComma
137+
)
134138
#else
135139
let newArgument: TypeSyntax = argumentElement.argument.erasingGenericTypes(genericTypes)
140+
let newArgumentElement = GenericArgumentSyntax(
141+
argument: newArgument,
142+
trailingComma: argumentElement.trailingComma
143+
)
136144
#endif
137-
let newArgumentElement = GenericArgumentSyntax(
138-
argument: newArgument,
139-
trailingComma: argumentElement.trailingComma
140-
)
141145
newArgumentElements.append(newArgumentElement)
142146
}
143147

Sources/SpyableMacro/Factories/ClosureFactory.swift

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,18 @@ struct ClosureFactory {
3636
let genericTypes = protocolFunctionDeclaration.genericTypes
3737
let returnClause = returnClause(protocolFunctionDeclaration: protocolFunctionDeclaration)
3838

39+
#if canImport(SwiftSyntax600)
40+
let effectSpecifiers = TypeEffectSpecifiersSyntax(
41+
asyncSpecifier: functionSignature.effectSpecifiers?.asyncSpecifier,
42+
throwsClause: functionSignature.effectSpecifiers?.throwsClause
43+
)
44+
#else
45+
let effectSpecifiers = TypeEffectSpecifiersSyntax(
46+
asyncSpecifier: functionSignature.effectSpecifiers?.asyncSpecifier,
47+
throwsSpecifier: functionSignature.effectSpecifiers?.throwsSpecifier
48+
)
49+
#endif
50+
3951
let elements = TupleTypeElementListSyntax {
4052
TupleTypeElementSyntax(
4153
type: FunctionTypeSyntax(
@@ -46,10 +58,7 @@ struct ClosureFactory {
4658
)
4759
}
4860
},
49-
effectSpecifiers: TypeEffectSpecifiersSyntax(
50-
asyncSpecifier: functionSignature.effectSpecifiers?.asyncSpecifier,
51-
throwsSpecifier: functionSignature.effectSpecifiers?.throwsSpecifier
52-
),
61+
effectSpecifiers: effectSpecifiers,
5362
returnClause: returnClause
5463
)
5564
)
@@ -166,7 +175,13 @@ struct ClosureFactory {
166175
expression = AwaitExprSyntax(expression: expression)
167176
}
168177

169-
if functionSignature.effectSpecifiers?.throwsSpecifier != nil {
178+
#if canImport(SwiftSyntax600)
179+
let throwsSpecifier = functionSignature.effectSpecifiers?.throwsClause?.throwsSpecifier
180+
#else
181+
let throwsSpecifier = functionSignature.effectSpecifiers?.throwsSpecifier
182+
#endif
183+
184+
if throwsSpecifier != nil {
170185
expression = TryExprSyntax(expression: expression)
171186
}
172187

@@ -188,12 +203,9 @@ struct ClosureFactory {
188203

189204
extension FunctionParameterListSyntax.Element {
190205
fileprivate var isInoutParameter: Bool {
191-
if let attributedType = self.type.as(AttributedTypeSyntax.self),
192-
attributedType.specifier?.text == TokenSyntax.keyword(.inout).text
193-
{
194-
return true
195-
} else {
196-
return false
197-
}
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(TokenSyntax.keyword(.inout).text)
198210
}
199211
}

Sources/SpyableMacro/Factories/FunctionImplementationFactory.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,13 @@ struct FunctionImplementationFactory {
8787
)
8888
}
8989

90-
if protocolFunctionDeclaration.signature.effectSpecifiers?.throwsSpecifier != nil {
90+
#if canImport(SwiftSyntax600)
91+
let throwsSpecifier = protocolFunctionDeclaration.signature.effectSpecifiers?.throwsClause?.throwsSpecifier
92+
#else
93+
let throwsSpecifier = protocolFunctionDeclaration.signature.effectSpecifiers?.throwsSpecifier
94+
#endif
95+
96+
if throwsSpecifier != nil {
9197
throwableErrorFactory.throwErrorExpression(variablePrefix: variablePrefix)
9298
}
9399

Sources/SpyableMacro/Factories/SpyFactory.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,14 @@ struct SpyFactory {
157157
parameterList: parameterList
158158
)
159159
}
160+
161+
#if canImport(SwiftSyntax600)
162+
let throwsSpecifier = functionDeclaration.signature.effectSpecifiers?.throwsClause?.throwsSpecifier
163+
#else
164+
let throwsSpecifier = functionDeclaration.signature.effectSpecifiers?.throwsSpecifier
165+
#endif
160166

161-
if functionDeclaration.signature.effectSpecifiers?.throwsSpecifier != nil {
167+
if throwsSpecifier != nil {
162168
try throwableErrorFactory.variableDeclaration(variablePrefix: variablePrefix)
163169
}
164170

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)