# Macro diagnostic position ignored?

**URL:** <https://forums.swift.org/t/macro-diagnostic-position-ignored/78640>\
**Category:** Macros\
**Created:** [March 19, 2025, 1:56am UTC](https://forums.swift.org/t/macro-diagnostic-position-ignored/78640 "2025-03-19T01:56:26Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![stephencelis](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/stephencelis/32/2675_2.png) [@stephencelis](https://forums.swift.org/u/stephencelis)\
**Post date:** [March 19, 2025, 1:56am UTC](https://forums.swift.org/t/macro-diagnostic-position-ignored/78640/1 "2025-03-19T01:56:26Z")

</div>

I'm trying to add some static analysis to a string passed to a macro, and am explicitly giving the associated diagnostic a position in the string, but Xcode appears to ignore it:

 ![image](https://global.discourse-cdn.com/swift/original/3X/6/a/6a26dc76a6c97e373b51373445336e40af9d510b.png)

In the above example, the diagnostic is positioned at the `(` character in the string, but the highlighting is done at the node level, which is the beginning of the string literal.

Am I mishandling SwiftSyntax in some way? Is this an Xcode bug?

---

<div class="post-metadata">

**Author:** ![ahoppen](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/ahoppen/32/36046_2.png) [@ahoppen](https://forums.swift.org/u/ahoppen)\
**Post date:** [March 19, 2025, 5:05am UTC](https://forums.swift.org/t/macro-diagnostic-position-ignored/78640/2 "2025-03-19T05:05:58Z")

</div>

Do you receive the expected diagnostic highlights when you compile on the command line? If so, this is likely an Xcode issue and an issue at [http://feedbackassistant.apple.com](http://feedbackassistant.apple.com) would be appreciated for that.

---

<div class="post-metadata">

**Author:** ![stephencelis](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/stephencelis/32/2675_2.png) [@stephencelis](https://forums.swift.org/u/stephencelis)\
**Post date:** [March 19, 2025, 5:15am UTC](https://forums.swift.org/t/macro-diagnostic-position-ignored/78640/3 "2025-03-19T05:15:50Z")

</div>

Nope, it appears to affect the compiler output as well:

```swift
….swift:153:8: warning: Cannot find ')' to match opening '(' in SQL string, producing incomplete fragment; did you mean to make this explicit? (from macro 'sql')
151 | 
152 | func f() {
153 | #sql("SELECT (1", as: Int.self)
    | |- warning: Cannot find ')' to match opening '(' in SQL string, producing incomplete fragment; did you mean to make this explicit? (from macro 'sql')
    | `- note: Use 'SQLQueryExpression.init(_:)' to silence this warning
154 | }
155 | 

```

I will note that we have a custom macro snapshot tool that uses SwiftSyntax's diagnostics formatter and things _are_ anchored correctly:

 ![image](https://global.discourse-cdn.com/swift/original/3X/3/8/38eae383ea62d7e361007f048b3d3cb8b811ec1f.png)

---

<div class="post-metadata">

**Author:** ![ahoppen](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/ahoppen/32/36046_2.png) [@ahoppen](https://forums.swift.org/u/ahoppen)\
**Post date:** [March 19, 2025, 5:28am UTC](https://forums.swift.org/t/macro-diagnostic-position-ignored/78640/4 "2025-03-19T05:28:17Z")

</div>

It looks like we loose the character-based source location somewhere in the compiler and switch to the token-anchored locations somewhere. Could you file an issue with a reproducer project to [GitHub - swiftlang/swift: The Swift Programming Language](https://github.com/swiftlang/swift)?

---

<div class="post-metadata">

**Author:** ![stephencelis](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/stephencelis/32/2675_2.png) [@stephencelis](https://forums.swift.org/u/stephencelis)\
**Post date:** [March 19, 2025, 5:37am UTC](https://forums.swift.org/t/macro-diagnostic-position-ignored/78640/5 "2025-03-19T05:37:39Z")

</div>

Done: [Compiler loses position offset of macro diagnostic · Issue #80110 · swiftlang/swift · GitHub](https://github.com/swiftlang/swift/issues/80110)
