Xcode unable to expand macro when macro name matches name of existing type?

Hi! I'm running into problems expanding a macro when that macro name matches the name of an existing type. It's possible this is an Xcode issue (not a swift-syntax issue)… but I don't see anyway to expand a macro outside of Xcode to confirm where this might be broken from. I'm also not sure if this behavior is intended.

The SwiftData.Query type is available to engineers as both a struct[1] and a macro[2]. When developers implement the Query with a macro, they don't have the ability to expand the macro from Xcode:

I can implement a small demo branch from swift-syntax to repro on a new macro.[3]

The demo branch defines a PropertyWrapper and Wrapper macro (that map to the same implementation). The macro injects an instance of a new custom type (also named PropertyWrapper).

public struct PropertyWrapper<T> {
  private var storage: T
  
  public init(storage: T) {
    self.storage = storage
  }
  
  public var wrappedValue: T {
    get {
      print("Getting value \(self.storage)")
      return self.storage
    }
    
    set {
      print("Setting value \(newValue)")
      self.storage = newValue
    }
  }
}

The playground defines a new type:

struct Name {
  @Wrapper var first: String = ""
  @PropertyWrapper var last: String = ""
}

Trying to expand the PropertyWrapper macro (which overloads the name of the PropertyWrapper struct) leads to the same missing functionality from SwiftData.Query:

Trying to expand the Wrapper reveals the option we were previously missing:

Is it possible that Xcode is unable to expand a macro that overloads the name of an existing type? AFAIK I don't have a way to expand a macro outside of Xcode to confirm.[4]

Is it possible this behavior is intended? Is there any more advice or documentation you could share about that? Thanks!


  1. Query | Apple Developer Documentation ↩︎

  2. Query() | Apple Developer Documentation ↩︎

  3. property wrapper · vanvoorden/swift-syntax@3c2a488 · GitHub ↩︎

  4. Expand macros in Swift file from command line? - #3 by ahoppen ↩︎

This is an issue inside Xcode. Could you file a feedback for the issue at bugreport.apple.com?

1 Like

@ahoppen Sounds good. Thanks!

This looks fixed in Xcode_16_Release_Candidate. Thanks!