Skip to content

Commit 68066e2

Browse files
committed
[Macros] Fix mangling scheme in the basic macro expansion context
1 parent 2b43cfb commit 68066e2

File tree

2 files changed

+3
-4
lines changed

2 files changed

+3
-4
lines changed

Sources/SwiftSyntaxMacros/BasicMacroExpansionContext.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,10 @@ extension BasicMacroExpansionContext: MacroExpansionContext {
122122
resultString += "fMu"
123123

124124
// Mangle the index.
125-
if uniqueIndex == 0 {
126-
resultString += "_"
127-
} else {
125+
if uniqueIndex > 0 {
128126
resultString += "\(uniqueIndex - 1)"
129127
}
128+
resultString += "_"
130129

131130
return TokenSyntax(.identifier(resultString), presence: .present)
132131
}

Tests/SwiftSyntaxMacrosTest/MacroSystemTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -732,7 +732,7 @@ final class MacroSystemTests: XCTestCase {
732732
let t2 = context.createUniqueName("mine")
733733
XCTAssertNotEqual(t1.description, t2.description)
734734
XCTAssertEqual(t1.description, "__macro_local_4minefMu_")
735-
XCTAssertEqual(t2.description, "__macro_local_4minefMu0")
735+
XCTAssertEqual(t2.description, "__macro_local_4minefMu0_")
736736
}
737737

738738
func testContextIndependence() {

0 commit comments

Comments
 (0)