Commit 1808310
committed
Make sure
A user was using code like
function make(): tuple<uint64> {
return (b"\x00\x00".to_uint(spicy::ByteOrder::Big), );
}
Before this patch this would generate a tuple constructor from an an
naked `uint64_t` which failed in the conversion to the expected safe
integer at C++ compilation time with a pretty cryptic C++ compiler error
/spicy/hilti/runtime/include/hilti/rt/3rdparty/SafeInt/SafeInt.hpp:5538:52: error: incomplete definition of type 'GetCastMethod<unsigned long long, std::tuple<std::optional<unsigned long long>>>'
5538 | SafeCastHelper< T, U, GetCastMethod< T, U >::method >::template CastThrow< E >( i, m_int );
| ~~~~~~~~~~~~~~~~~~~~~^~ /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.2.sdk/usr/include/c++/v1/optional:337:9: note: in instantiation of function template specialization 'SafeInt<unsigned long long, hilti::rt::integer::det
ail::SafeIntException>::SafeInt<std::tuple<std::optional<unsigned long long>>>' requested here
337 | : __val_(std::forward<_Args>(__args)...), __engaged_(true) {}
| ^ /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.2.sdk/usr/include/c++/v1/optional:686:57: note: in instantiation of function template specialization 'std::__optional_destruct_base<SafeInt<unsigned lon
g long, hilti::rt::integer::detail::SafeIntException>>::__optional_destruct_base<std::tuple<std::optional<unsigned long long>>>' requested here
686 | _LIBCPP_HIDE_FROM_ABI constexpr optional(_Up&& __v) : __base(in_place, std::forward<_Up>(__v)) {}
| ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.2.sdk/usr/include/c++/v1/optional:686:57: note: (skipping 1 context in backtrace; use -ftemplate-backtrace-limit=0 to see all)
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.2.sdk/usr/include/c++/v1/tuple:345:9: note: in instantiation of function template specialization 'std::optional<SafeInt<unsigned long long, hilti::rt::i
nteger::detail::SafeIntException>>::optional<std::tuple<std::optional<unsigned long long>>, 0>' requested here
345 | : __value_(std::forward<_Tp>(__t)) {
| ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.2.sdk/usr/include/c++/v1/tuple:473:9: note: in instantiation of function template specialization 'std::__tuple_leaf<0, std::optional<SafeInt<unsigned lo
ng long, hilti::rt::integer::detail::SafeIntException>>>::__tuple_leaf<std::tuple<std::optional<unsigned long long>>, void>' requested here
473 | : __tuple_leaf<_Uf, _Tf>(std::forward<_Up>(__u))..., __tuple_leaf<_Ul, _Tl>()... {}
| ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.2.sdk/usr/include/c++/v1/tuple:620:9: note: in instantiation of function template specialization 'std::__tuple_impl<std::__tuple_indices<0>, std::option
al<SafeInt<unsigned long long, hilti::rt::integer::detail::SafeIntException>>>::__tuple_impl<0UL, std::optional<SafeInt<unsigned long long, hilti::rt::integer::detail::SafeIntException>>, std::tuple<std::optional<unsigned long long>>>' requeste$
here
620 | : __base_(typename __make_tuple_indices<sizeof...(_Up)>::type(),
| ^
/private/var/folders/ht/vtb0rkbd4ws15vx02xdb84zw0000gn/T/foo_5591707596a5ab7-1743e21b33c7da2.cc:36:12: note: in instantiation of function template specialization 'std::tuple<std::optional<SafeInt<unsigned long long, hilti::rt::integer::detail::S
afeIntException>>>::tuple<std::tuple<std::optional<unsigned long long>>, 0>' requested here
36 | return hilti::rt::tuple::make_from_optionals(hilti::rt::tuple::wrap_expression([&]() { return "\000\000"_b.toUInt(::hilti::rt::ByteOrder{::hilti::rt::ByteOrder::Big}); }));
| ^
The only way to work around that would have been to explicitly create a
temporary integer and use that, e.g.,
function make(): tuple<uint64> {
local x = b"\x00\x00".to_uint(spicy::ByteOrder::Big);
return (x, );
}
With this patch this works like expected.
(cherry picked from commit 94a4441)bytes::to[U]Int returns runtime integers.1 parent 84c3404 commit 1808310
2 files changed
+5
-5
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
477 | 477 | | |
478 | 478 | | |
479 | 479 | | |
480 | | - | |
| 480 | + | |
481 | 481 | | |
482 | 482 | | |
483 | 483 | | |
| |||
486 | 486 | | |
487 | 487 | | |
488 | 488 | | |
489 | | - | |
| 489 | + | |
490 | 490 | | |
491 | 491 | | |
492 | 492 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
171 | 171 | | |
172 | 172 | | |
173 | 173 | | |
174 | | - | |
175 | | - | |
| 174 | + | |
| 175 | + | |
176 | 176 | | |
177 | 177 | | |
178 | 178 | | |
| |||
185 | 185 | | |
186 | 186 | | |
187 | 187 | | |
188 | | - | |
| 188 | + | |
189 | 189 | | |
190 | 190 | | |
191 | 191 | | |
| |||
0 commit comments