From 12c7391bd7e538d4d8af43ce8368444435f6654a Mon Sep 17 00:00:00 2001 From: yuriy0 Date: Mon, 14 Jun 2021 18:29:19 -0400 Subject: [PATCH] Bug fix: correct RTTI for AttributeInvocable (#1004) * Bug fix: correct RTTI for AttributeInvocable * Allow test case to crash if RTTI is wrong * Revert "Allow test case to crash if RTTI is wrong" Based on PR feedback, this change adds no value to the test and is confusing. This reverts commit 6c36065c3759d857cc16ab011d09167261181141. * Remove perhaps confusing comments and add a more to the point comment Co-authored-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> --- .../AzCore/AzCore/RTTI/ReflectContext.h | 2 +- Code/Framework/AzCore/Tests/Serialization.cpp | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/Code/Framework/AzCore/AzCore/RTTI/ReflectContext.h b/Code/Framework/AzCore/AzCore/RTTI/ReflectContext.h index e03823888a..5b27cb9f88 100644 --- a/Code/Framework/AzCore/AzCore/RTTI/ReflectContext.h +++ b/Code/Framework/AzCore/AzCore/RTTI/ReflectContext.h @@ -274,7 +274,7 @@ namespace AZ { using Callable = AZStd::conditional_t::value, AZStd::function::function_type>, Invocable>; public: - AZ_RTTI((AttributeInvocable, "{60D5804F-9AF4-4EB1-8F5A-62AFB4883F9D}"), AZ::Attribute); + AZ_RTTI((AttributeInvocable, "{60D5804F-9AF4-4EB1-8F5A-62AFB4883F9D}", Invocable), AZ::Attribute); AZ_CLASS_ALLOCATOR(AttributeInvocable, SystemAllocator, 0); template explicit AttributeInvocable(CallableType&& invocable) diff --git a/Code/Framework/AzCore/Tests/Serialization.cpp b/Code/Framework/AzCore/Tests/Serialization.cpp index 036942f9dd..4dba972324 100644 --- a/Code/Framework/AzCore/Tests/Serialization.cpp +++ b/Code/Framework/AzCore/Tests/Serialization.cpp @@ -2010,6 +2010,28 @@ TEST_F(SerializeBasicTest, BasicTypeTest_Succeed) } + + /* + This test will dynamic cast (azrtti_cast) between incompatible types, which should always result in nullptr. + If this test fails, the RTTI declaration for the relevant type is incorrect. + */ + TEST_F(Serialization, AttributeRTTI) + { + { + AttributeInvocable> fn([](AZStd::string x) { return x + x; }); + Attribute* fnDownCast = &fn; + auto fnUpCast = azrtti_cast>*>(fnDownCast); + EXPECT_EQ(fnUpCast, nullptr); + } + + { + AttributeFunction fn([](AZStd::string x) { return x + x; }); + Attribute* fnDownCast = &fn; + auto fnUpCast = azrtti_cast*>(fnDownCast); + EXPECT_EQ(fnUpCast, nullptr); + } + } + /* * Deprecation */