1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 19:47:44 +00:00

LibWasm: Allow Value::to<T>() to perform statically valid conversions

e.g. i32 -> i16 (if within range).
This commit is contained in:
Ali Mohammad Pur 2023-04-05 00:41:23 +03:30 committed by Ali Mohammad Pur
parent b10da81c7c
commit eceb244bef

View file

@ -126,10 +126,12 @@ public:
Optional<T> result;
m_value.visit(
[&](auto value) {
if constexpr (IsSame<T, decltype(value)>)
result = value;
else if constexpr (!IsFloatingPoint<T> && IsSame<decltype(value), MakeSigned<T>>)
result = value;
if constexpr (IsSame<T, decltype(value)> || (!IsFloatingPoint<T> && IsSame<decltype(value), MakeSigned<T>>)) {
result = static_cast<T>(value);
} else if constexpr (!IsFloatingPoint<T> && IsConvertible<decltype(value), T>) {
if (AK::is_within_range<T>(value))
result = static_cast<T>(value);
}
},
[&](Reference const& value) {
if constexpr (IsSame<T, Reference>) {