AST: Requestify lookup of protocol referenced by ImplementsAttr

Direct lookup relied in primary file checking to have filled in the
protocol type stored in the ImplementsAttr. This was already wrong
with multi-file test cases in non-WMO mode, and crashed in the
ASTPrinter if printing a declaration in a non-primary file.

I don't have a standalone test case that is independent of my
upcoming ASTPrinter changes, but this is a nice cleanup regardless.
This commit is contained in:
Slava Pestov
2023-05-18 13:53:04 -04:00
parent 8ccabbdae8
commit 7499c222ee
10 changed files with 121 additions and 92 deletions

View File

@@ -417,16 +417,12 @@ deriveEquatable_eq(
// Add the @_implements(Equatable, ==(_:_:)) attribute
if (generatedIdentifier != C.Id_EqualsOperator) {
auto equatableProto = C.getProtocol(KnownProtocolKind::Equatable);
auto equatableTy = equatableProto->getDeclaredInterfaceType();
auto equatableTyExpr = TypeExpr::createImplicit(equatableTy, C);
SmallVector<Identifier, 2> argumentLabels = { Identifier(), Identifier() };
auto equalsDeclName = DeclName(C, DeclBaseName(C.Id_EqualsOperator),
argumentLabels);
eqDecl->getAttrs().add(new (C) ImplementsAttr(SourceLoc(),
SourceRange(),
equatableTyExpr,
equalsDeclName,
DeclNameLoc()));
eqDecl->getAttrs().add(ImplementsAttr::create(parentDC,
equatableProto,
equalsDeclName));
}
if (!C.getEqualIntDecl()) {