Skip to content

Commit 106b321

Browse files
authored
Merge pull request #28609 from eeckstein/fix-remangler
Demangler: support protocols as parents of bound generic types to avoid crash in the indexer for invalid swift code.
2 parents 5eac3e2 + f860a9b commit 106b321

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

lib/Demangling/Remangler.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,12 @@ void Remangler::mangleAnyNominalType(Node *node) {
487487
void Remangler::mangleGenericArgs(Node *node, char &Separator,
488488
bool fullSubstitutionMap) {
489489
switch (node->getKind()) {
490+
case Node::Kind::Protocol:
491+
// A protocol cannot be the parent of a nominal type, so this case should
492+
// never be hit by valid swift code. But the indexer might generate a URL
493+
// from invalid swift code, which has a bound generic inside a protocol.
494+
// The ASTMangler treats a protocol like any other nominal type in this
495+
// case, so we also support it in the remangler.
490496
case Node::Kind::Structure:
491497
case Node::Kind::Enum:
492498
case Node::Kind::Class:

test/Demangle/Inputs/manglings.txt

+1
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,7 @@ _$S3BBBBf0602365061_ ---> _$S3BBBBf0602365061_
328328
_$S3BBBBi0602365061_ ---> _$S3BBBBi0602365061_
329329
_$S3BBBBv0602365061_ ---> _$S3BBBBv0602365061_
330330
_T0lxxxmmmTk ---> _T0lxxxmmmTk
331+
$s4Test5ProtoP8IteratorV10collectionAEy_qd__Gqd___tcfc ---> Test.Proto.Iterator.init(collection: A1) -> Test.Proto.Iterator<A1>
331332
$s4test3fooV4blahyAA1SV1fQryFQOy_Qo_AHF ---> test.foo.blah(<<opaque return type of test.S.f() -> some>>.0) -> <<opaque return type of test.S.f() -> some>>.0
332333
$S3nix8MystructV1xACyxGx_tcfc7MyaliasL_ayx__GD ---> Myalias #1 in nix.Mystruct<A>.init(x: A) -> nix.Mystruct<A>
333334
$S3nix7MyclassCfd7MyaliasL_ayx__GD ---> Myalias #1 in nix.Myclass<A>.deinit

0 commit comments

Comments
 (0)