Thanks for being a part of WWDC25!

How did we do? We’d love to know your thoughts on this year’s conference. Take the survey here

New unexpected compile behavior in Xcode 16.3

I have a macro that converts expression into a string literal, e.g.:

#toString(variable) -> "variable"
#toString(TypeName) -> "TypeName"
#toString(\TypeName.property) -> "property"

In Xcode 16.3 #toString(TypeName) stopped to work, compilation throws 'Expected member name or initializer call after type name' error. Everything works fine in Xcode 16.2. I tried to compare build settings between 16.2 and 16.3 but haven't noticed differences that may cause this new error.

The following works in both Xcode versions:

#toString(variable) -> "variable"
#toString(\TypeName.property) -> "property"

Seems like Xcode tries to compile code that shouldn't be compiled because of macro expansion.

Does anybody know what new has appeared in 16.3 and, perhaps, how to fix the problem?

Same found in my project, we have

@attached(member, names: arbitrary)
public macro MacroName<each U: ProtocolName>(_ name: repeat (each U).Type) =
  #externalMacro(module: "MacroModule", type: "MacroType")

and calling it

@MacroName(ImplementationOfProtocol)
struct Something { ...... }

class ImplementationOfProtocol: ProtocolName {}

Seeing error "Expected member name or initializer call after type name"

Bug report: FB17081839.

I think you might get more traction on this issue oven on Swift Forums, and specifically the Development > Macros topic area there.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Accepted Answer

Turned out that this is Xcode 16.3 which does it correctly.

According to the Expression Macros design, macro parameters should be type-checked, so the macro implementation doesn't receive incorrect code as input.

Thus Xcode <=16.2 erroneously allowed the wrong expression to be passed into my macro implementation, and this is fixed in Xcode 16.3.

Glad you got it sorted.

For those following along at home, samkudr’s thread on Swift Forums is here.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

New unexpected compile behavior in Xcode 16.3
 
 
Q