I'm trying to write a Macro, get used to it. I'm facing sme problems and I realize I don't really understand What something like String.Type and String.self means.
Was wondering if someone could explain things and help me understand why I'm facing this error (or maybe I can do it myself after reading the explanation):
P.S. The whole cast might seem odd to you, the reason I'm doing it is because using po node or any other lldb command in the debugger will not yield anything, node is not recognized, not even with frame variable show.
Firstly, if you're trying to print a variable that's generic using LLVM debugging, a reliable workaround is to replace generics written as some with a generic parameter clause within the function, as demonstrated below:
-public static func expansion(
- of node: some FreestandingMacroExpansionSyntax,
- in context: some MacroExpansionContext
) -> ExprSyntax {
+public static func expansion<Node: FreestandingMacroExpansionSyntax, Context: MacroExpansionContext>(
+ of node: Node,
+ in context: Context
) -> ExprSyntax {
Regarding the error you encountered, Type 'any FreestandingMacroExpansionSyntax' cannot conform to 'SyntaxProtocol', it arises when you attempt to pass a protocol where a type is expected. To cast the node to a protocol, consider using SyntaxProtocol.asProtocol(_:).