Skip to content

Commit 5780a9f

Browse files
committed
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.
1 parent 9e3d67e commit 5780a9f

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

lib/AST/ASTContext.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2564,6 +2564,12 @@ BoundGenericType::BoundGenericType(TypeKind theKind,
25642564
BoundGenericType *BoundGenericType::get(NominalTypeDecl *TheDecl,
25652565
Type Parent,
25662566
ArrayRef<Type> GenericArgs) {
2567+
assert(TheDecl->getGenericParams() && "must be a generic type decl");
2568+
assert((!Parent || Parent->is<NominalType>() ||
2569+
Parent->is<BoundGenericType>() ||
2570+
Parent->is<UnboundGenericType>()) &&
2571+
"parent must be a nominal type");
2572+
25672573
ASTContext &C = TheDecl->getDeclContext()->getASTContext();
25682574
llvm::FoldingSetNodeID ID;
25692575
RecursiveTypeProperties properties;
@@ -2609,6 +2615,13 @@ BoundGenericType *BoundGenericType::get(NominalTypeDecl *TheDecl,
26092615
}
26102616

26112617
NominalType *NominalType::get(NominalTypeDecl *D, Type Parent, const ASTContext &C) {
2618+
assert((isa<ProtocolDecl>(D) || !D->getGenericParams()) &&
2619+
"must be a non-generic type decl");
2620+
assert((!Parent || Parent->is<NominalType>() ||
2621+
Parent->is<BoundGenericType>() ||
2622+
Parent->is<UnboundGenericType>()) &&
2623+
"parent must be a nominal type");
2624+
26122625
switch (D->getKind()) {
26132626
case DeclKind::Enum:
26142627
return EnumType::get(cast<EnumDecl>(D), Parent, C);

0 commit comments

Comments
 (0)