From de4b665298ab33496c036d15260f0c98a0ce7fbd Mon Sep 17 00:00:00 2001 From: Shannon Booth Date: Fri, 29 May 2026 21:47:42 +0200 Subject: [PATCH] AK: Fix rvalue Variant downcast to variant aliases Pass the required TypeWrapper through the rvalue downcast> path, matching the existing const& overload. --- AK/Variant.h | 2 +- Tests/AK/TestVariant.cpp | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/AK/Variant.h b/AK/Variant.h index b812b362af..17d81debec 100644 --- a/AK/Variant.h +++ b/AK/Variant.h @@ -430,7 +430,7 @@ public: decltype(auto) downcast() && { if constexpr (sizeof...(NewTs) == 1 && (IsSpecializationOf && ...)) { - return move(*this).template downcast_variant(); + return move(*this).downcast_variant(TypeWrapper {}); } else { Variant instance { Variant::invalid_index, Detail::VariantConstructTag {} }; visit([&](auto& value) { diff --git a/Tests/AK/TestVariant.cpp b/Tests/AK/TestVariant.cpp index d97f58019a..9ed2631961 100644 --- a/Tests/AK/TestVariant.cpp +++ b/Tests/AK/TestVariant.cpp @@ -132,6 +132,11 @@ TEST_CASE(as) EXPECT(one_integer_to_rule_them_all.has()); EXPECT_EQ(fake_integer.get(), 60); EXPECT_EQ(one_integer_to_rule_them_all.get(), 60); + + using OptionalFancyType = Variant; + auto definitely_fancy = OptionalFancyType { static_cast(12) }.downcast(); + EXPECT(definitely_fancy.has()); + EXPECT_EQ(definitely_fancy.get(), 12); } TEST_CASE(moved_from_state)