From 0974463daf0982626cb2b8c8bb6f494f3e6c9e52 Mon Sep 17 00:00:00 2001 From: Anders Leino Date: Mon, 10 Jun 2024 15:15:02 +0300 Subject: Fix typos in the docs (#4322) --- docs/design/casting.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs/design/casting.md') 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. -- cgit v1.2.3