AST: Always-on ASSERTs for ProtocolConformanceRef

If any of the get*() methods are called on the wrong kind of
ProtocolConformanceRef, we immediately cast a pointer to an
incorrect type, which will most likely cause a crash.
This commit is contained in:
Slava Pestov
2025-03-18 09:40:47 -04:00
parent 012ac5da5d
commit efbeaea969
2 changed files with 4 additions and 2 deletions

View File

@@ -19,6 +19,7 @@
#include "swift/AST/ProtocolConformanceRef.h"
#include "swift/AST/Type.h"
#include "swift/AST/TypeAlignments.h"
#include "swift/Basic/Assertions.h"
#include "swift/Basic/Debug.h"
#include "llvm/ADT/Hashing.h"
#include "llvm/ADT/PointerUnion.h"
@@ -101,6 +102,7 @@ public:
return !isInvalid() && Union.is<ProtocolConformance*>();
}
ProtocolConformance *getConcrete() const {
ASSERT(isConcrete());
return Union.get<ProtocolConformance*>();
}
@@ -108,6 +110,7 @@ public:
return !isInvalid() && Union.is<PackConformance*>();
}
PackConformance *getPack() const {
ASSERT(isPack());
return Union.get<PackConformance*>();
}
@@ -116,6 +119,7 @@ public:
}
ProtocolDecl *getAbstract() const {
ASSERT(isAbstract());
return Union.get<ProtocolDecl*>();
}