[Macros] Don't visit macro-generated extensions in 'visitAuxiliaryDecls'.

Macro-generated extensions are hoisted to file scope, because extensions are
not valid in nested scopes. Callers of 'visitAuxiliaryDecls' assume that the
auxiliary decls are in the same decl context as the original, which is clearly
not the case for extensions, and it leads to issues like visiting extension at
the wrong time during SILGen. The extensions are already added to the top-level
decls, so we don't need to visit them as auxiliary decls, and we can type-check
macro-expanded decls at the end of visitation in TypeCheckDeclPrimary.
This commit is contained in:
Holly Borla
2023-06-23 18:44:30 -07:00
parent 3676379302
commit 83030a9c63
11 changed files with 67 additions and 43 deletions

View File

@@ -4104,8 +4104,7 @@ void FileUnit::getTopLevelDeclsWithAuxiliaryDecls(
getTopLevelDecls(nonExpandedDecls);
for (auto *decl : nonExpandedDecls) {
decl->visitAuxiliaryDecls([&](Decl *auxDecl) {
if (!isa<ExtensionDecl>(auxDecl))
results.push_back(auxDecl);
results.push_back(auxDecl);
});
results.push_back(decl);
}