From d288e0ba10c34fd72c9fef95d92f48fcb651b581 Mon Sep 17 00:00:00 2001 From: leftibot Date: Fri, 10 Apr 2026 22:04:05 -0600 Subject: [PATCH] Address review: remove const_override, set const flag directly on Type_Info Replace the m_const_override bool on Boxed_Value::Data with a Type_Info::make_const() method that sets the const bit in m_flags directly. This ensures constness is visible everywhere consistently, including places that check get_type_info().is_const() directly. Requested by @lefticus in PR #643 review. Co-Authored-By: Claude Opus 4.6 (1M context) --- include/chaiscript/dispatchkit/boxed_value.hpp | 9 +++++---- include/chaiscript/dispatchkit/type_info.hpp | 2 ++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/include/chaiscript/dispatchkit/boxed_value.hpp b/include/chaiscript/dispatchkit/boxed_value.hpp index 58e271b4..89a0ed2f 100644 --- a/include/chaiscript/dispatchkit/boxed_value.hpp +++ b/include/chaiscript/dispatchkit/boxed_value.hpp @@ -47,7 +47,6 @@ namespace chaiscript { m_data_ptr = rhs.m_data_ptr; m_const_data_ptr = rhs.m_const_data_ptr; m_return_value = rhs.m_return_value; - m_const_override = rhs.m_const_override; if (rhs.m_attrs) { m_attrs = std::make_unique>>(*rhs.m_attrs); @@ -68,7 +67,6 @@ namespace chaiscript { std::unique_ptr>> m_attrs; bool m_is_ref; bool m_return_value; - bool m_const_override{false}; }; struct Object_Data { @@ -157,10 +155,13 @@ namespace chaiscript { /// return true if the object is uninitialized bool is_undef() const noexcept { return m_data->m_type_info.is_undef(); } - bool is_const() const noexcept { return m_data->m_type_info.is_const() || m_data->m_const_override; } + bool is_const() const noexcept { return m_data->m_type_info.is_const(); } /// Mark this Boxed_Value as const (used for script-level const declarations) - void make_const() noexcept { m_data->m_const_override = true; } + void make_const() noexcept { + m_data->m_type_info.make_const(); + m_data->m_data_ptr = nullptr; + } bool is_type(const Type_Info &ti) const noexcept { return m_data->m_type_info.bare_equal(ti); } diff --git a/include/chaiscript/dispatchkit/type_info.hpp b/include/chaiscript/dispatchkit/type_info.hpp index 2f21ee58..c77e9fac 100644 --- a/include/chaiscript/dispatchkit/type_info.hpp +++ b/include/chaiscript/dispatchkit/type_info.hpp @@ -85,6 +85,8 @@ namespace chaiscript { constexpr const std::type_info *bare_type_info() const noexcept { return m_bare_type_info; } + void make_const() noexcept { m_flags |= (1 << is_const_flag); } + private: struct Unknown_Type { };