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:
Erik Eckstein
2024-10-01 09:30:18 +02:00
parent fadff007a1
commit 7f43e52c45
2 changed files with 26 additions and 0 deletions

View File

@@ -1013,6 +1013,20 @@ namespace llvm {
}
};
template<class FromTy>
struct CastInfo<::swift::GenericContext, FromTy, std::enable_if_t<is_simple_type<FromTy>::value>>
: public CastIsPossible<::swift::GenericContext, FromTy>,
public DefaultDoCastIfPossible<::swift::GenericContext *, FromTy,
CastInfo<::swift::GenericContext, FromTy>> {
static inline ::swift::GenericContext *castFailed() { return nullptr; }
static inline ::swift::GenericContext *doCast(const FromTy &val) {
auto *genCtxt = val->getAsGenericContext();
assert(genCtxt);
return const_cast<::swift::GenericContext *>(genCtxt);
}
};
template<class FromTy>
struct CastInfo<::swift::IterableDeclContext, FromTy, std::enable_if_t<is_simple_type<FromTy>::value>>
: public CastIsPossible<::swift::IterableDeclContext, FromTy>,