|
25 | 25 | #include "swift/AST/GenericSignature.h"
|
26 | 26 | #include "swift/AST/Initializer.h"
|
27 | 27 | #include "swift/AST/LazyResolver.h"
|
| 28 | +#include "swift/AST/LocalArchetypeRequirementCollector.h" |
28 | 29 | #include "swift/AST/MacroDiscriminatorContext.h"
|
29 | 30 | #include "swift/AST/Module.h"
|
30 | 31 | #include "swift/AST/Ownership.h"
|
@@ -3733,29 +3734,48 @@ void ASTMangler::appendAssociatedTypeName(DependentMemberType *dmt,
|
3733 | 3734 |
|
3734 | 3735 | void ASTMangler::appendClosureEntity(
|
3735 | 3736 | const SerializedAbstractClosureExpr *closure) {
|
| 3737 | + assert(!closure->getType()->hasLocalArchetype() && |
| 3738 | + "Not enough information here to handle this case"); |
| 3739 | + |
3736 | 3740 | appendClosureComponents(closure->getType(), closure->getDiscriminator(),
|
3737 |
| - closure->isImplicit(), closure->getParent()); |
| 3741 | + closure->isImplicit(), closure->getParent(), |
| 3742 | + ArrayRef<GenericEnvironment *>()); |
3738 | 3743 | }
|
3739 | 3744 |
|
3740 | 3745 | void ASTMangler::appendClosureEntity(const AbstractClosureExpr *closure) {
|
3741 |
| - appendClosureComponents(closure->getType(), closure->getDiscriminator(), |
3742 |
| - isa<AutoClosureExpr>(closure), closure->getParent()); |
| 3746 | + ArrayRef<GenericEnvironment *> capturedEnvs; |
| 3747 | + |
| 3748 | + auto type = closure->getType(); |
| 3749 | + |
| 3750 | + // FIXME: CodeCompletionResultBuilder calls printValueDeclUSR() but the |
| 3751 | + // closure hasn't been type checked yet. |
| 3752 | + if (!type) |
| 3753 | + type = ErrorType::get(closure->getASTContext()); |
| 3754 | + |
| 3755 | + if (type->hasLocalArchetype()) |
| 3756 | + capturedEnvs = closure->getCaptureInfo().getGenericEnvironments(); |
| 3757 | + |
| 3758 | + appendClosureComponents(type, closure->getDiscriminator(), |
| 3759 | + isa<AutoClosureExpr>(closure), closure->getParent(), |
| 3760 | + capturedEnvs); |
3743 | 3761 | }
|
3744 | 3762 |
|
3745 | 3763 | void ASTMangler::appendClosureComponents(Type Ty, unsigned discriminator,
|
3746 | 3764 | bool isImplicit,
|
3747 |
| - const DeclContext *parentContext) { |
| 3765 | + const DeclContext *parentContext, |
| 3766 | + ArrayRef<GenericEnvironment *> capturedEnvs) { |
3748 | 3767 | assert(discriminator != AbstractClosureExpr::InvalidDiscriminator
|
3749 | 3768 | && "closure must be marked correctly with discriminator");
|
3750 | 3769 |
|
3751 | 3770 | BaseEntitySignature base(parentContext->getInnermostDeclarationDeclContext());
|
3752 | 3771 | appendContext(parentContext, base, StringRef());
|
3753 | 3772 |
|
3754 |
| - if (!Ty) |
3755 |
| - Ty = ErrorType::get(parentContext->getASTContext()); |
3756 |
| - |
3757 | 3773 | auto Sig = parentContext->getGenericSignatureOfContext();
|
3758 |
| - Ty = Ty->mapTypeOutOfContext(); |
| 3774 | + |
| 3775 | + Ty = Ty.subst(MapLocalArchetypesOutOfContext(Sig, capturedEnvs), |
| 3776 | + MakeAbstractConformanceForGenericType(), |
| 3777 | + SubstFlags::PreservePackExpansionLevel); |
| 3778 | + |
3759 | 3779 | appendType(Ty->getCanonicalType(), Sig);
|
3760 | 3780 | appendOperator(isImplicit ? "fu" : "fU", Index(discriminator));
|
3761 | 3781 | }
|
|
0 commit comments