# \[Pitch\] Swift Testing macro for getting the current source location

**URL:** <https://forums.swift.org/t/pitch-swift-testing-macro-for-getting-the-current-source-location/87025>\
**Category:** Pitches\
**Tags:** swift-testing\
**Created:** [June 1, 2026, 6:29pm UTC](https://forums.swift.org/t/pitch-swift-testing-macro-for-getting-the-current-source-location/87025 "2026-06-01T18:29:20Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![grynspan](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/grynspan/32/15315_2.png) [@grynspan](https://forums.swift.org/u/grynspan)\
**Post date:** [June 1, 2026, 6:29pm UTC](https://forums.swift.org/t/pitch-swift-testing-macro-for-getting-the-current-source-location/87025/1 "2026-06-01T18:29:20Z")

</div>

Swift Testing includes a type, [`SourceLocation`](https://developer.apple.com/documentation/testing/sourcelocation), that represents the precise location of something in a file (typically a .swift file). Various Swift Testing API takes an instance of this type in order to correctly attribute diagnostics and test issues that occur at test time.

Swift Testing currently provides a `#_sourceLocation` macro that expands, at compile time, to an expression that generates an instance of `SourceLocation`, similar to how `#fileID`, `#line`, etc. work. This macro, being underscored, is not formally supported, nor does it appear in Swift Testing's documentation.

I propose we introduce a non-underscored macro and formally support this pattern. For more details, see the full proposal [here](https://github.com/swiftlang/swift-evolution/blob/jgrynspan/sourcelocation-macro/proposals/testing/NNNN-sourcelocation-macro.md).

---

<div class="post-metadata">

**Author:** ![maartene](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/maartene/32/42076_2.png) [@maartene](https://forums.swift.org/u/maartene)\
**Post date:** [June 1, 2026, 6:41pm UTC](https://forums.swift.org/t/pitch-swift-testing-macro-for-getting-the-current-source-location/87025/2 "2026-06-01T18:41:32Z")

</div>

sounds like a no-brainer to me. 🚢 it

On a serious note:

I assume the plan would be: for some time both `#SourceLocation` and `#_sourceLocation` exist side by side, where the latter is deprecated? And after some time `#_sourceLocation` gets removed?

---

<div class="post-metadata">

**Author:** ![grynspan](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/grynspan/32/15315_2.png) [@grynspan](https://forums.swift.org/u/grynspan)\
**Post date:** [June 1, 2026, 6:45pm UTC](https://forums.swift.org/t/pitch-swift-testing-macro-for-getting-the-current-source-location/87025/3 "2026-06-01T18:45:12Z")

</div>

> [@maartene](#):
>
> I assume the plan would be: for some time both `#SourceLocation` and `#_sourceLocation` exist side by side, where the latter is deprecated? And after some time `#_sourceLocation` gets removed?

Likely `#_sourceLocation` would stick around until a major language change (i.e. Swift 7) but otherwise yes, it'll just sit there as a compatibility name in perpetuity.

---

<div class="post-metadata">

**Author:** ![Mordil](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/mordil/32/5840_2.png) [@Mordil](https://forums.swift.org/u/Mordil)\
**Post date:** [June 1, 2026, 6:46pm UTC](https://forums.swift.org/t/pitch-swift-testing-macro-for-getting-the-current-source-location/87025/4 "2026-06-01T18:46:27Z")

</div>

Seems straight forward to me, it's just unfortunate about the FilePath thing preventing this being in the Standard Library

---

<div class="post-metadata">

**Author:** ![maartene](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/maartene/32/42076_2.png) [@maartene](https://forums.swift.org/u/maartene)\
**Post date:** [June 1, 2026, 6:46pm UTC](https://forums.swift.org/t/pitch-swift-testing-macro-for-getting-the-current-source-location/87025/5 "2026-06-01T18:46:37Z")

</div>

I can’t believe I’m actually typing this, but considering #\_sourceLocation was never supported and going to the supported version is a search-replace. Maybe we can sunset it sooner than a new major version?

---

<div class="post-metadata">

**Author:** ![Jon\_Shier](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/jon_shier/32/921_2.png) [@Jon\_Shier](https://forums.swift.org/u/Jon_Shier)\
**Post date:** [June 1, 2026, 6:47pm UTC](https://forums.swift.org/t/pitch-swift-testing-macro-for-getting-the-current-source-location/87025/6 "2026-06-01T18:47:15Z")

</div>

Having an evolvable, single value with all location info would be great, though I would hate to take the good `#sourceLocation` name for a macro that isn't generally available. Seems like we should just solve the `#filePath` issue first, then make it available from the standard library.

---

<div class="post-metadata">

**Author:** ![grynspan](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/grynspan/32/15315_2.png) [@grynspan](https://forums.swift.org/u/grynspan)\
**Post date:** [June 1, 2026, 6:47pm UTC](https://forums.swift.org/t/pitch-swift-testing-macro-for-getting-the-current-source-location/87025/7 "2026-06-01T18:47:33Z")

</div>

> [@maartene](#):
>
> Maybe we can sunset it sooner than a new major version?

This is a decision ultimately for the Testing Workgroup and review community to make, but there's no cost to keeping the old name around, and we did tell folks "wink-wink-nudge-nudge, you can use this underscored name", so… 🤷‍♂️

---

<div class="post-metadata">

**Author:** ![grynspan](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/grynspan/32/15315_2.png) [@grynspan](https://forums.swift.org/u/grynspan)\
**Post date:** [June 1, 2026, 6:51pm UTC](https://forums.swift.org/t/pitch-swift-testing-macro-for-getting-the-current-source-location/87025/8 "2026-06-01T18:51:33Z")

</div>

> [@Jon\_Shier](#):
>
> Having an evolvable, single value with all location info would be great, though I would hate to take the good `#sourceLocation` name for a macro that isn't generally available. Seems like we should just solve the `#filePath` issue first, then make it available from the standard library.

In a hypothetical future where this macro _is_ in the stdlib, Swift Testing would presumably migrate over to that definition. If the macro cannot move to the stdlib (for whatever reason!), it's moot really.

---

<div class="post-metadata">

**Author:** ![smontgomery](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/smontgomery/32/965_2.png) [@smontgomery](https://forums.swift.org/u/smontgomery)\
**Post date:** [August 10, 2026, 7:18pm UTC](https://forums.swift.org/t/pitch-swift-testing-macro-for-getting-the-current-source-location/87025/9 "2026-08-10T19:18:25Z")

</div>

This pitch has advanced to review, see [ST-0027: Macro for getting the current source location](https://forums.swift.org/t/st-0027-macro-for-getting-the-current-source-location/88743).
