diff options
| author | Anders Leino <aleino@nvidia.com> | 2024-06-10 15:15:02 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-06-10 05:15:02 -0700 |
| commit | 0974463daf0982626cb2b8c8bb6f494f3e6c9e52 (patch) | |
| tree | ed60c4a010edd13f310f0c170f2f82bd8b5a4329 /docs/design/casting.md | |
| parent | 9a23a9aab3721828526c921db1e779008e133e8f (diff) | |
Fix typos in the docs (#4322)
Diffstat (limited to 'docs/design/casting.md')
| -rw-r--r-- | docs/design/casting.md | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/docs/design/casting.md b/docs/design/casting.md index 6c4b119eb..80c1f149f 100644 --- a/docs/design/casting.md +++ b/docs/design/casting.md @@ -25,7 +25,7 @@ These functions will also work with types that do not have Vtbl - like IRInst de Both 'as' and 'dynamicCast' handle the case if the pointer is a nullptr, by returning a nullptr. If the cast succeeds the cast pointer is returned otherwise nullptr is returned. If a cast is performed with a free function it always returns a raw pointer. -So why have 'as' and 'dynamicCast' - they seem sort of similar? The primary difference is dynamicCast *must* always return a pointer to the same object, whilst 'as' *can* return a pointer to a different object if that is the desired 'normal' casting behavior for the type. This is the case for Type* when using 'as' it may return a different object - the 'canonical type' for the Type*. For a concrete example take 'NamedExpressionType', it's canonical type is the type the name relates to. If you use 'as' on it - it will produce a pointer to a different object, an object that will not be castable back into a NamedExpressionType. +So why have 'as' and 'dynamicCast' - they seem sort of similar? The primary difference is dynamicCast *must* always return a pointer to the same object, whilst 'as' *can* return a pointer to a different object if that is the desired 'normal' casting behavior for the type. This is the case for Type* when using 'as' it may return a different object - the 'canonical type' for the Type*. For a concrete example take 'NamedExpressionType', its canonical type is the type the name relates to. If you use 'as' on it - it will produce a pointer to a different object, an object that will not be castable back into a NamedExpressionType. Also keep in mind that 'as' behavior is based on the pointer type being cast from. For any pointer to a type derived from Type it will cast the canonical type. **BUT** if the pointer is pointing to a Type derived *object*, but the pointer type is *not* derived from Type (like say RefObject*), then 'as' will behave like dynamicCast. |
