mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
AST: fix casting from Decl to GenericContext
Fixes `cast<GenericContext>(someDecl)`. I don't know why this didn't show up as a crash so far. But slightly changing `Decl` results in a wrong type cast and a crash.
This commit is contained in:
@@ -1568,6 +1568,8 @@ public:
|
||||
/// Retrieve the position of any where clause for this context's
|
||||
/// generic parameters.
|
||||
SourceRange getGenericTrailingWhereClauseSourceRange() const;
|
||||
|
||||
static bool classof(const Decl *D);
|
||||
};
|
||||
static_assert(sizeof(_GenericContext) + sizeof(DeclContext) ==
|
||||
sizeof(GenericContext), "Please add fields to _GenericContext");
|
||||
@@ -9589,6 +9591,16 @@ inline bool DeclContext::classof(const Decl *D) {
|
||||
}
|
||||
}
|
||||
|
||||
inline bool GenericContext::classof(const Decl *D) {
|
||||
switch (D->getKind()) { //
|
||||
default: return false;
|
||||
#define DECL(ID, PARENT) // See previous line
|
||||
#define GENERIC_DECL(ID, PARENT) \
|
||||
case DeclKind::ID: return true;
|
||||
#include "swift/AST/DeclNodes.def"
|
||||
}
|
||||
}
|
||||
|
||||
inline DeclContext *DeclContext::castDeclToDeclContext(const Decl *D) {
|
||||
// XXX -- ModuleDecl is not defined in Decl.h, but because DeclContexts
|
||||
// preface decls in memory, any DeclContext type will due.
|
||||
|
||||
Reference in New Issue
Block a user