Skip to content

[Macros] Look further up the syntax tree to find the type we need #64196

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 8, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions lib/ASTGen/Sources/ASTGen/Macros.swift
Original file line number Diff line number Diff line change
Expand Up @@ -422,13 +422,17 @@ private func findSyntaxNodeInSourceFile<Node: SyntaxProtocol>(
return nil
}

// Dig out its parent.
guard let parentSyntax = token.parent else {
print("not on a macro expansion node: \(token.recursiveDescription)")
return nil
var currentSyntax = Syntax(token)
while let parentSyntax = currentSyntax.parent {
if let typedParent = parentSyntax.as(type) {
return typedParent
}

currentSyntax = parentSyntax
}

return parentSyntax.as(type)
print("unable to find node: \(token.recursiveDescription)")
return nil
}

@_cdecl("swift_ASTGen_expandAttachedMacro")
Expand Down