mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
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:
@@ -2564,6 +2564,12 @@ BoundGenericType::BoundGenericType(TypeKind theKind,
|
|||||||
BoundGenericType *BoundGenericType::get(NominalTypeDecl *TheDecl,
|
BoundGenericType *BoundGenericType::get(NominalTypeDecl *TheDecl,
|
||||||
Type Parent,
|
Type Parent,
|
||||||
ArrayRef<Type> GenericArgs) {
|
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();
|
ASTContext &C = TheDecl->getDeclContext()->getASTContext();
|
||||||
llvm::FoldingSetNodeID ID;
|
llvm::FoldingSetNodeID ID;
|
||||||
RecursiveTypeProperties properties;
|
RecursiveTypeProperties properties;
|
||||||
@@ -2609,6 +2615,13 @@ BoundGenericType *BoundGenericType::get(NominalTypeDecl *TheDecl,
|
|||||||
}
|
}
|
||||||
|
|
||||||
NominalType *NominalType::get(NominalTypeDecl *D, Type Parent, const ASTContext &C) {
|
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()) {
|
switch (D->getKind()) {
|
||||||
case DeclKind::Enum:
|
case DeclKind::Enum:
|
||||||
return EnumType::get(cast<EnumDecl>(D), Parent, C);
|
return EnumType::get(cast<EnumDecl>(D), Parent, C);
|
||||||
|
|||||||
Reference in New Issue
Block a user