Skip to content

Error during @Suite expansion when comment is on the same line  #777

@bkhouri

Description

@bkhouri

Description

The @Suite macro is expanding to incorrect code.

If we have

@Suite(
    .serialized // my comment
)
struct AsyncProcessTests.self {
   // Includes @Test definitions
}

A compilation error occurs.

Expected behavior

Compilation fails with the following

`- /Users/bkhouri/Documents/git/public/swiftlang/swift-package-manager-2/Tests/BasicsTests/AsyncProcessTests.swift:508:1: note: expanded code originates here
506 |         #expect(result.exitStatus == .terminated(code: 0))
507 |     }
508 | }
    +--- macro expansion @Suite ----------------------------------------
    | 7 |                 AsyncProcessTests.self,
    | 8 |                 traits: [
    | 9 |             .serialized // my comment],sourceLocation: Testing.SourceLocation(fileID: "BasicsTests/AsyncProcessTests.swift", filePath: "/Users/bkhouri/Documents/git/public/swiftlang/swift-package-manager-2/Tests/BasicsTests/AsyncProcessTests.swift", line: 26, column: 2)
    |   |              `- error: expected ',' separator
    |10 |               )
    |11 |             ]
    +-------------------------------------------------------------------
509 | 
510 | extension AsyncProcess {

Actual behavior

The code comment should be ignore and compilation should not occur.

Steps to reproduce

  1. Create the following file
    import Testing
    
    @Suite(
        .serialized // my comment
    )
    struct MyTestStructure {}
    
  2. run swift test

swift-testing version/commit hash

Unknown

Swift & OS version (output of swift --version ; uname -a)

Mac OS 15.x

❯ swift --version
swift-driver version: 1.115 Apple Swift version 6.0.2 (swiftlang-6.0.2.1.2 clang-1600.0.26.4)
Target: arm64-apple-macosx15.0

Metadata

Metadata

Assignees

Labels

bug🪲 Something isn't workingtraitsIssues and PRs related to the trait subsystem or built-in traits

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions