13
13
#include " swift/IDE/CompletionLookup.h"
14
14
#include " CodeCompletionResultBuilder.h"
15
15
#include " ExprContextAnalysis.h"
16
+ #include " swift/AST/GenericEnvironment.h"
17
+ #include " swift/AST/GenericSignature.h"
16
18
#include " swift/AST/ParameterList.h"
17
19
#include " swift/AST/SourceFile.h"
18
20
@@ -555,15 +557,10 @@ Type CompletionLookup::eraseArchetypes(Type type, GenericSignature genericSig) {
555
557
if (!genericSig)
556
558
return type;
557
559
558
- auto buildProtocolComposition = [&](ArrayRef<ProtocolDecl *> protos) -> Type {
559
- SmallVector<Type, 2 > types;
560
- for (auto proto : protos)
561
- types.push_back (proto->getDeclaredInterfaceType ());
562
- return ProtocolCompositionType::get (Ctx, types,
563
- /* HasExplicitAnyObject=*/ false );
564
- };
565
-
566
560
if (auto *genericFuncType = type->getAs <GenericFunctionType>()) {
561
+ assert (genericFuncType->getGenericSignature ()->isEqual (genericSig) &&
562
+ " if not, just use the GFT's signature instead below" );
563
+
567
564
SmallVector<AnyFunctionType::Param, 8 > erasedParams;
568
565
for (const auto ¶m : genericFuncType->getParams ()) {
569
566
auto erasedTy = eraseArchetypes (param.getPlainType (), genericSig);
@@ -584,15 +581,24 @@ Type CompletionLookup::eraseArchetypes(Type type, GenericSignature genericSig) {
584
581
archetypeType->isRoot ())
585
582
return t;
586
583
587
- auto protos = archetypeType->getConformsTo ();
588
- if (!protos.empty ())
589
- return buildProtocolComposition (protos);
584
+ auto genericSig = archetypeType->getGenericEnvironment ()->getGenericSignature ();
585
+ auto upperBound = genericSig->getUpperBound (
586
+ archetypeType->getInterfaceType (),
587
+ /* forExistentialSelf=*/ false ,
588
+ /* withParameterizedProtocols=*/ false );
589
+
590
+ if (!upperBound->isAny ())
591
+ return upperBound;
590
592
}
591
593
592
594
if (t->isTypeParameter ()) {
593
- const auto protos = genericSig->getRequiredProtocols (t);
594
- if (!protos.empty ())
595
- return buildProtocolComposition (protos);
595
+ auto upperBound = genericSig->getUpperBound (
596
+ t,
597
+ /* forExistentialSelf=*/ false ,
598
+ /* withParameterizedProtocols=*/ false );
599
+
600
+ if (!upperBound->isAny ())
601
+ return upperBound;
596
602
}
597
603
598
604
return t;
0 commit comments