diff --git a/inkcpp/numeric_operations.h b/inkcpp/numeric_operations.h index 489919b4..d2593139 100644 --- a/inkcpp/numeric_operations.h +++ b/inkcpp/numeric_operations.h @@ -116,6 +116,7 @@ namespace casting // int value can cast to float case value_type::int32: return static_cast(v.get()); case value_type::uint32: return static_cast(v.get()); + case value_type::boolean: return v.get() ? 1.0f : 0.0f; default: inkFail("invalid numeric_cast!"); return 0; } } diff --git a/inkcpp/operations.h b/inkcpp/operations.h index 48080beb..7546a015 100644 --- a/inkcpp/operations.h +++ b/inkcpp/operations.h @@ -86,15 +86,16 @@ template ink::runtime::internal::value ink::runtime::internal::value::redefine(const value& oth, T&... env) const { - if (type() != oth.type() && (type() == value_type::list_flag || type() == value_type::list) - && (oth.type() == value_type::list_flag || oth.type() == value_type::list)) { - /// @todo could break origin - if (oth.type() == value_type::list) { - return value{}.set(oth.get()); - } else { - return value{}.set(oth.get()); - } + if (type() != oth.type()) { + + const value vs[] = {*this, oth}; + inkAssert( + casting::common_base<2>(vs) != value_type::none, + "try to redefine value of other type with no cast available" + ); + + // There's a valid conversion, so redefine as input value. + return oth; } - inkAssert(type() == oth.type(), "try to redefine value of other type"); return redefine(oth, {&env...}); }