Skip to content

filePathMode: .filePath breaks macro expansion on Windows #85958

@stefanspringer1

Description

@stefanspringer1

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:

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
)

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
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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions