ITADN

filePathMode: .filePath breaks macro expansion on Windows

#3193Openstefanspringer1 创建于 2025-11-23
bug
S
stefanspringer1commented
### Description From my forums forums topic https://forums.swift.org/t/macro-expansion-failing-involving-sourcelocation/83250: The code I used at one place is: ```swift 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`): ```swift context.location( of: declaration.body!.statements, at: .beforeLeadingTrivia, filePathMode: .fileID ) ``` But with `.fileID` the relocation of errors does not work, so the `.filePath` seems to be needed and a correction of the described problem is important. ### Steps to Reproduce 1. Check out https://github.com/stefanspringer1/Pipeline.git at commit number a8445b6ac3b5ecb8185647528ba4ce96e6784247 (tag: 1.0.12). 2. Building including the tests (`swift build --build-test`) is successful on macOS 3. Building including the tests on Windows results in the errors ```text 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 ... ``` ### Environment - Swift 6.2.1 on Windows (x86_64 and ARM) and macOS. - swift-syntax 602.0.0.
1 条评论