From 7c9c42329e453c0c1e70ec37efcf5375065b3567 Mon Sep 17 00:00:00 2001 From: YongDo-Hyun Date: Sat, 27 Dec 2025 01:16:53 +0300 Subject: fix: prevent widening of stored tag type in value assignment; update test output handling Signed-off-by: YongDo-Hyun --- src/value.cpp | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) (limited to 'src/value.cpp') diff --git a/src/value.cpp b/src/value.cpp index 273049baf9..f07e28d82c 100644 --- a/src/value.cpp +++ b/src/value.cpp @@ -98,17 +98,12 @@ namespace // helper functions local to this translation unit auto incoming_type = detail::get_primitive_type::value; // If the existing tag is of a narrower type than the incoming type, - // replace it with a new tag of the incoming type so the value is not - // truncated. Otherwise set the existing tag (possibly narrowing). + // reject the assignment to avoid widening the stored tag type. auto existing_type = tag_ptr->get_type(); if(static_cast(existing_type) < static_cast(incoming_type)) { - // replace with a new, wider tag that preserves the value - tag_ptr = make_numeric_tag(incoming_type, val); - if(!tag_ptr) - throw std::bad_cast(); - return; + throw std::bad_cast(); } // Existing type is same or wider: write into the existing tag (may narrow) -- cgit 0.0.5-2-1-g0f52