Skip to content

Commit 4a8b7bd

Browse files
committed
AST: Sink SubstFlags::DesugarMemberTypes hack down into ProtocolConformance::getTypeWitness()
1 parent 9afff03 commit 4a8b7bd

File tree

2 files changed

+23
-20
lines changed

2 files changed

+23
-20
lines changed

lib/AST/ProtocolConformance.cpp

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,27 @@ ProtocolConformance::getTypeWitnessAndDecl(AssociatedTypeDecl *assocType,
147147

148148
Type ProtocolConformance::getTypeWitness(AssociatedTypeDecl *assocType,
149149
SubstOptions options) const {
150-
return getTypeWitnessAndDecl(assocType, options).getWitnessType();
150+
auto witness = getTypeWitnessAndDecl(assocType, options);
151+
auto witnessTy = witness.getWitnessType();
152+
if (!witnessTy)
153+
return witnessTy;
154+
155+
// This is a hacky feature allowing code completion to migrate to
156+
// using Type::subst() without changing output.
157+
//
158+
// FIXME: Remove this hack and do whatever we need to do in the
159+
// ASTPrinter instead.
160+
if (options & SubstFlags::DesugarMemberTypes) {
161+
if (auto *aliasType = dyn_cast<TypeAliasType>(witnessTy.getPointer()))
162+
witnessTy = aliasType->getSinglyDesugaredType();
163+
164+
// Another hack. If the type witness is a opaque result type. They can
165+
// only be referred using the name of the associated type.
166+
if (witnessTy->is<OpaqueTypeArchetypeType>())
167+
witnessTy = witness.getWitnessDecl()->getDeclaredInterfaceType();
168+
}
169+
170+
return witnessTy;
151171
}
152172

153173
ConcreteDeclRef

lib/AST/TypeSubstitution.cpp

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -579,25 +579,8 @@ Type TypeSubstituter::transformDependentMemberType(DependentMemberType *dependen
579579
witnessTy = conformance.getPack()->getTypeWitness(assocType,
580580
IFS.getOptions());
581581
} else if (conformance.isConcrete()) {
582-
auto witness =
583-
conformance.getConcrete()->getTypeWitnessAndDecl(assocType,
584-
IFS.getOptions());
585-
586-
witnessTy = witness.getWitnessType();
587-
if (!witnessTy || witnessTy->hasError())
588-
return failed();
589-
590-
// This is a hacky feature allowing code completion to migrate to
591-
// using Type::subst() without changing output.
592-
if (IFS.getOptions() & SubstFlags::DesugarMemberTypes) {
593-
if (auto *aliasType = dyn_cast<TypeAliasType>(witnessTy.getPointer()))
594-
witnessTy = aliasType->getSinglyDesugaredType();
595-
596-
// Another hack. If the type witness is a opaque result type. They can
597-
// only be referred using the name of the associated type.
598-
if (witnessTy->is<OpaqueTypeArchetypeType>())
599-
witnessTy = witness.getWitnessDecl()->getDeclaredInterfaceType();
600-
}
582+
witnessTy = conformance.getConcrete()->getTypeWitness(assocType,
583+
IFS.getOptions());
601584
}
602585

603586
if (!witnessTy || witnessTy->is<ErrorType>())

0 commit comments

Comments
 (0)