Macro expansion failing involving #sourceLocation

I have a package with a macro (Pipeline), and its tests pass on macOS with Swift 6.2.1, but in Windows (ARM) also with Swift 6.2.1 I get the following errors:

macro expansion @Step:3:5: error: '#sourceLocation' cannot be an extended escaping string literal
...
macro expansion @Step:10:5: error: parameterless closing #sourceLocation() directive without prior opening #sourceLocation(file:,line:) directive
...

For both, swift-syntax is resolved to version 600.0.1.

I find it strange that those two results differ, and also what could be wrong?

The responsible code is there: Pipeline/Sources/StepMacros/StepMacro.swift at main · stefanspringer1/Pipeline · GitHub

CC: @Douglas_Gregor @rintaro

1 Like

The code I used at one place is:

context.location(
    of: declaration.body!.statements,
    at: .beforeLeadingTrivia,
    filePathMode: .filePath
)

The file path on Windows involves backslashes, I am guessing that this leads to the file path being written as #"..."# in the outer macro expansion which in turn leads to the described error. The compilation errors in the above package (you have to build including the tests: swift build --build-tests) are absent if I use the following code (with .fileID instead of .filePath):

context.location(
    of: declaration.body!.statements,
    at: .beforeLeadingTrivia,
    filePathMode: .fileID
)

...It. seems that with .fileID the relocation of errors does not work, .filePath seems to be needed?? I will try some code changes, but it might be that the described problem on Windows needs to be resolved... :frowning:

I filed the issue filePathMode: .filePath breaks macro expansion on Windows · Issue #3193 · swiftlang/swift-syntax · GitHub.

I found a fix in my code see the issue (but I still think that should be resolved in Swift Syntax).