Skip to content

Commit ad20b8a

Browse files
committed
Put back HasCircularInheritedProtocolsRequest::evaluate.
1 parent d57a8d2 commit ad20b8a

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

lib/Sema/TypeCheckDecl.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,34 @@ static bool canSkipCircularityCheck(NominalTypeDecl *decl) {
233233
return decl->hasClangNode() || decl->wasDeserialized();
234234
}
235235

236+
bool
237+
HasCircularInheritedProtocolsRequest::evaluate(Evaluator &evaluator,
238+
ProtocolDecl *decl) const {
239+
if (canSkipCircularityCheck(decl))
240+
return false;
241+
242+
bool anyObject = false;
243+
auto inherited = getDirectlyInheritedNominalTypeDecls(decl, anyObject);
244+
for (auto &found : inherited) {
245+
auto *protoDecl = dyn_cast<ProtocolDecl>(found.Item);
246+
if (!protoDecl)
247+
continue;
248+
249+
// If we have a cycle, handle it and return true.
250+
auto result = evaluator(HasCircularInheritedProtocolsRequest{protoDecl});
251+
if (!result) {
252+
using Error = CyclicalRequestError<HasCircularInheritedProtocolsRequest>;
253+
llvm::handleAllErrors(result.takeError(), [](const Error &E) {});
254+
return true;
255+
}
256+
257+
// If the underlying request handled a cycle and returned true, bail.
258+
if (*result)
259+
return true;
260+
}
261+
return false;
262+
}
263+
236264
bool
237265
HasCircularRawValueRequest::evaluate(Evaluator &evaluator,
238266
EnumDecl *decl) const {

0 commit comments

Comments
 (0)