From 5f3a179b7382bffb58eee851cda390095e36fcd5 Mon Sep 17 00:00:00 2001 From: willvale <66674079+willvale@users.noreply.github.com> Date: Fri, 21 Nov 2025 22:19:14 +1300 Subject: [PATCH 1/2] Fix restrictive numeric casts/assignments. Allow type conversion on redefine if the casting matrix says the types have a common base. Allow bool->float conversion. --- inkcpp/numeric_operations.h | 1 + inkcpp/operations.h | 16 +++++++--------- 2 files changed, 8 insertions(+), 9 deletions(-) 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..d1422ef2 100644 --- a/inkcpp/operations.h +++ b/inkcpp/operations.h @@ -86,15 +86,13 @@ 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...}); } From adefe3ee0b7b9f3be23790d76b7f80775133bddf Mon Sep 17 00:00:00 2001 From: willvale <66674079+willvale@users.noreply.github.com> Date: Fri, 21 Nov 2025 22:30:55 +1300 Subject: [PATCH 2/2] Clangformat fixes. --- inkcpp/operations.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/inkcpp/operations.h b/inkcpp/operations.h index d1422ef2..7546a015 100644 --- a/inkcpp/operations.h +++ b/inkcpp/operations.h @@ -88,8 +88,11 @@ ink::runtime::internal::value { 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"); + 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;