Hi, I'm trying out the MemberMacro and I just want the macro to add a subscript to the struct or class its applied to.
public struct SearchableMacro: MemberMacro {
static public func expansion(of node: AttributeSyntax,
providingMembersOf declaration: some DeclGroupSyntax,
in context: some MacroExpansionContext) throws -> [DeclSyntax] {
return [
DeclSyntax(try SubscriptDeclSyntax("""
subscript(key: String) -> Any? {
guard let keyPath = Self.keys[key] else {
return nil
}
return self[keyPath: kp]
}
"""))
]
}
}
The problem I'm having is that when the macro is applied a space character is added between the self
and the [
in the last return. The output I see in my test looks like this:
failed - Actual output (+) differed from expected output (-):
struct Hello {
subscript(key: String) -> Any? {
guard let keyPath = Self.keys[key] else {
return nil
}
– return self[keyPath: kp]
+ return self [keyPath: kp]
}
}
Could this be a bug or am I missing something here?