[SourceKit] Workaround a bug that parameterized protocols without 'any' cannot be mangled

`typealias` is currently allowed to refer to a protocol without the `any` keyword. This breaks mangling the typealias type into a USR will crash because parameterized protocols are expected to be `any` types.

Implement a SourceKit-specific minimal workaround for that problem by not computing USRs for parameterized protocols.

rdar://98623438
This commit is contained in:
Alex Hoppen
2022-08-25 13:02:51 +02:00
parent fd4e98a51e
commit c8a7e55f6a
4 changed files with 69 additions and 0 deletions

View File

@@ -948,6 +948,22 @@ fillSymbolInfo(CursorSymbolInfo &Symbol, const DeclInfo &DInfo,
}
Symbol.TypeName = copyAndClearString(Allocator, Buffer);
// ParameterizedProtocolType should always be wrapped in ExistentialType and
// cannot be mangled on its own.
// But ParameterizedProtocolType can currently occur in 'typealias'
// declarations. rdar://99176683
// To avoid crashing in USR generation, return an error for now.
if (auto Ty = DInfo.VD->getInterfaceType()) {
while (auto MetaTy = Ty->getAs<MetatypeType>()) {
Ty = MetaTy->getInstanceType();
}
if (Ty && Ty->getCanonicalType()->is<ParameterizedProtocolType>()) {
return llvm::createStringError(
llvm::inconvertibleErrorCode(),
"Cannot mangle USR for ParameterizedProtocolType without 'any'.");
}
}
SwiftLangSupport::printDeclTypeUSR(DInfo.VD, OS);
Symbol.TypeUSR = copyAndClearString(Allocator, Buffer);