Description
Description
ASTScope
seems to be introducing generic parameters before macro declaration parameters in unqualified lookup.
Reproduction
I’ve discovered the behavior when working on SwiftLexicalLookup
and using validation function described in this PR. When running validation for this snippet from the Swift standard library:
@freestanding(expression)
public macro externalMacro<T>(module: String, type: String) -> T = Builtin.ExternalMacro
I received the following output from ASTScope
(left):
-----> Lookup started at: 2:39 ("String") finishInSequentialScope: false
| ASTScope | SwiftLexicalLookup
> ❌ | T 2:28 | module 2:31
> ℹ️ | Omitted ASTScope name: T 2:28
> ❌ | module 2:31 | type 2:47
> ❌ | type 2:47 | T 2:28
Expected behavior
In function, initializer, subscript and nominal type declarations, generic parameters always come after function parameters. I found the behavior of ASTScope
as unexpected, because I assumed the lookup rules to be the same in all the mentioned cases. The expected order of the unqualified lookup is given on the right side of the table above (as currently modeled by SwiftLexicalLookup
).
Environment
Swift version 6.1-dev (LLVM 95f3fb07f8f5294, Swift 9695ff4)
Target: arm64-apple-darwin24.0.0
Additional information
After a brief discussion with @DougGregor, he mentioned the issue could be caused by the „flattened” implementation of macro declaration in ASTScope
. He also suggested I should file this issue.