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