AST: Add some assertions when constructing nominal types

Make sure we don't build BoundGenericTypes out of non-generic decls,
or NominalTypes out of generic decls.
This commit is contained in:
Slava Pestov
2016-11-03 00:04:30 -07:00
parent 9e3d67ea27
commit 5780a9f525

View File

@@ -2564,6 +2564,12 @@ BoundGenericType::BoundGenericType(TypeKind theKind,
BoundGenericType *BoundGenericType::get(NominalTypeDecl *TheDecl,
Type Parent,
ArrayRef<Type> GenericArgs) {
assert(TheDecl->getGenericParams() && "must be a generic type decl");
assert((!Parent || Parent->is<NominalType>() ||
Parent->is<BoundGenericType>() ||
Parent->is<UnboundGenericType>()) &&
"parent must be a nominal type");
ASTContext &C = TheDecl->getDeclContext()->getASTContext();
llvm::FoldingSetNodeID ID;
RecursiveTypeProperties properties;
@@ -2609,6 +2615,13 @@ BoundGenericType *BoundGenericType::get(NominalTypeDecl *TheDecl,
}
NominalType *NominalType::get(NominalTypeDecl *D, Type Parent, const ASTContext &C) {
assert((isa<ProtocolDecl>(D) || !D->getGenericParams()) &&
"must be a non-generic type decl");
assert((!Parent || Parent->is<NominalType>() ||
Parent->is<BoundGenericType>() ||
Parent->is<UnboundGenericType>()) &&
"parent must be a nominal type");
switch (D->getKind()) {
case DeclKind::Enum:
return EnumType::get(cast<EnumDecl>(D), Parent, C);