Description
Motivation
Create a Swift Testing target and define 2 test functions. Give both functions the same name:
import Testing
@Test func someTest() {}
@Test func someTest() {}
Expected behavior:
A nice compiler error of the form "Invalid redeclaration of 'someTest`
Observed behavior:
The compiler crashes during macro expansion.
$ swift build --build-tests
Building for debugging...
error: emit-module command failed with exit code 1 (use -v to see invocation)
macro expansion @Test:2:25: error: invalid redeclaration of '$s41SwiftTestingTwoTestFuncsWithSameNameTests04someD00D0fMp_8f5bed0c2fMu_()'
`- …/SwiftTestingTwoTestFuncsWithSameNameTests.swift:4:25: note: expanded code originates here
2 | import SwiftTestingTwoTestFuncsWithSameName
3 |
4 | @Test func someTest() {}
+--- macro expansion @Test -------------------------------------------
| 1 | @available(*, deprecated, message: "This function is an implementation detail of the testing library. Do not use it directly.")
…
macro expansion @Test:10:6: error: invalid redeclaration of '$s41SwiftTestingTwoTestFuncsWithSameNameTests04someD00D0fMp_38__🟠$test_container__function__f5bed0c2fMu_'
`- …/SwiftTestingTwoTestFuncsWithSameNameTests.swift:4:25: note: expanded code originates here
When running the tests in Xcode, you see "Command SwiftCompile failed with a nonzero exit code" and need to dig into the build log to discover the actual issue, which isn't a good user experience.
Proposed solution
It would be nice to have a better diagnostic for this, especially because I believe this is a fairly common error to make when copy-pasting an existing test function.
Alternatives considered
No response
Additional information
I tested this on macOS 15.5 with Swift 6.1 (Xcode 16.4) and Swift 6.2 beta (Xcode 26.0 beta 2). The result is the same in both cases, except that Swift 6.2 also prints a stack trace, presumably because it's built with more assertions enabled?