Skip to content

Commit f2fb70d

Browse files
authored
[6.2] Fix a miscompile when a test function has a raw identifier parameter label. (#1173)
- **Explanation**: Fixes parsing of function names to preserve backticks for raw parameter labels. - **Scope**: `@Test` macro and parameterized tests. - **Issues**: #1167 - **Original PRs**: #1168 - **Risk**: No obvious risk. - **Testing**: Standard CI jobs should verify the fix. - **Reviewers**: @briancroom @stmontgomery @hamishknight
1 parent ae7fe60 commit f2fb70d

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

Sources/TestingMacros/TestDeclarationMacro.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,8 @@ public struct TestDeclarationMacro: PeerMacro, Sendable {
160160
for (label, parameter) in parametersWithLabels {
161161
if parameter.firstName.tokenKind == .wildcard {
162162
LabeledExprSyntax(expression: label)
163+
} else if let rawIdentifier = parameter.firstName.rawIdentifier {
164+
LabeledExprSyntax(label: "`\(rawIdentifier)`", expression: label)
163165
} else {
164166
LabeledExprSyntax(label: parameter.firstName.textWithoutBackticks, expression: label)
165167
}

Tests/TestingTests/MiscellaneousTests.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,11 @@ struct MiscellaneousTests {
315315
let displayName = try #require(suite.displayName)
316316
#expect(displayName == "Suite With De Facto Display Name")
317317
}
318+
319+
@Test(arguments: [0])
320+
func `Test with raw identifier and raw identifier parameter labels can compile`(`argument name` i: Int) {
321+
#expect(i == 0)
322+
}
318323
#endif
319324

320325
@Test("Free functions are runnable")

0 commit comments

Comments
 (0)