Skip to content

Commit b842d01

Browse files
committed
[Macros] Don't visit auxiliary decls of class members twice.
To ensure that class vtables get laid out with the right ABI, visiting a class declaration visits all of its "ABI members", which includes visiting all of the auxiliary declarations. However, we also visit the auxiliary declarations of every declaration, which means some declarations get visited twice. This led to another oddly-specific bug for macros, where we would visit declarations introduce by peer macros on class members twice. When combined with function-body-skipping (e.g., to emit a module file), this would result in spurious errors of the form: Expected '{' in body of function declaration Stop visiting the auxiliary declarations of class members twice, eliminating this error. This one has been annoying me off and on for a while :). Fixes rdar://107429169.
1 parent 4fef3c8 commit b842d01

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

lib/Sema/TypeCheckDeclPrimary.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1821,9 +1821,13 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
18211821

18221822
void visit(Decl *decl) {
18231823
// Visit auxiliary decls first.
1824-
decl->visitAuxiliaryDecls([&](Decl *auxiliaryDecl) {
1825-
this->visit(auxiliaryDecl);
1826-
});
1824+
// We don't do this for members of classes because it happens as part of
1825+
// visiting their ABI members.
1826+
if (!isa<ClassDecl>(decl->getDeclContext())) {
1827+
decl->visitAuxiliaryDecls([&](Decl *auxiliaryDecl) {
1828+
this->visit(auxiliaryDecl);
1829+
});
1830+
}
18271831

18281832
if (auto *Stats = getASTContext().Stats)
18291833
++Stats->getFrontendCounters().NumDeclsTypechecked;

test/Macros/macro_expand_peers.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,14 @@ func useCompletionHandlerG(s: S, _ body: @escaping (String) -> Void) {
6767
}
6868
}
6969

70+
class C {
71+
@addCompletionHandler
72+
func f(a: Int, for b: String, _ value: Double) async -> String {
73+
return b
74+
}
75+
}
76+
77+
7078
@addCompletionHandler
7179
func f(a: Int, for b: String, _ value: Double) async -> String {
7280
return b

0 commit comments

Comments
 (0)