AST: Repent for my sins by adding new assertions

Since the previous fix is essentially a hack to dodge an
assertion, I'm adding stronger assertions to
AbstractTypeParamDecl::getSuperclass() and
getConformingProtocols().
This commit is contained in:
Slava Pestov
2017-03-30 00:55:58 -07:00
parent f10f00d887
commit a79ef97c32

View File

@@ -2316,8 +2316,10 @@ UnboundGenericType *TypeAliasDecl::getUnboundGenericType() const {
} }
Type AbstractTypeParamDecl::getSuperclass() const { Type AbstractTypeParamDecl::getSuperclass() const {
auto *dc = getDeclContext(); auto *genericEnv = getDeclContext()->getGenericEnvironmentOfContext();
auto contextTy = dc->mapTypeIntoContext(getDeclaredInterfaceType()); assert(genericEnv != nullptr && "Too much circularity");
auto contextTy = genericEnv->mapTypeIntoContext(getDeclaredInterfaceType());
if (auto *archetype = contextTy->getAs<ArchetypeType>()) if (auto *archetype = contextTy->getAs<ArchetypeType>())
return archetype->getSuperclass(); return archetype->getSuperclass();
@@ -2327,8 +2329,10 @@ Type AbstractTypeParamDecl::getSuperclass() const {
ArrayRef<ProtocolDecl *> ArrayRef<ProtocolDecl *>
AbstractTypeParamDecl::getConformingProtocols() const { AbstractTypeParamDecl::getConformingProtocols() const {
auto *dc = getDeclContext(); auto *genericEnv = getDeclContext()->getGenericEnvironmentOfContext();
auto contextTy = dc->mapTypeIntoContext(getDeclaredInterfaceType()); assert(genericEnv != nullptr && "Too much circularity");
auto contextTy = genericEnv->mapTypeIntoContext(getDeclaredInterfaceType());
if (auto *archetype = contextTy->getAs<ArchetypeType>()) if (auto *archetype = contextTy->getAs<ArchetypeType>())
return archetype->getConformsTo(); return archetype->getConformsTo();