MemberMacro adds space to self inside subscript

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?

Probably a bug, I found a similar issue previously, I suggest filing an issue on swift-syntax

Sounds like an issue that will fixed by Teach TokenSpecSet about experimental features by hamishknight · Pull Request #2211 · apple/swift-syntax · GitHub

Yeah, absolutely. I did some tests on swift-syntax and the issue is already solved on the main branch.