mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 10:57:34 +00:00
LibWasm: Allow Value::to<T>() to perform statically valid conversions
e.g. i32 -> i16 (if within range).
This commit is contained in:
parent
b10da81c7c
commit
eceb244bef
1 changed files with 6 additions and 4 deletions
|
@ -126,10 +126,12 @@ public:
|
||||||
Optional<T> result;
|
Optional<T> result;
|
||||||
m_value.visit(
|
m_value.visit(
|
||||||
[&](auto value) {
|
[&](auto value) {
|
||||||
if constexpr (IsSame<T, decltype(value)>)
|
if constexpr (IsSame<T, decltype(value)> || (!IsFloatingPoint<T> && IsSame<decltype(value), MakeSigned<T>>)) {
|
||||||
result = value;
|
result = static_cast<T>(value);
|
||||||
else if constexpr (!IsFloatingPoint<T> && IsSame<decltype(value), MakeSigned<T>>)
|
} else if constexpr (!IsFloatingPoint<T> && IsConvertible<decltype(value), T>) {
|
||||||
result = value;
|
if (AK::is_within_range<T>(value))
|
||||||
|
result = static_cast<T>(value);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
[&](Reference const& value) {
|
[&](Reference const& value) {
|
||||||
if constexpr (IsSame<T, Reference>) {
|
if constexpr (IsSame<T, Reference>) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue