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:
@@ -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>,
|
||||
|
||||
Reference in New Issue
Block a user