Hex string formatter check incorrectly rejected slices.

This commit is contained in:
Christoffer Lerno
2025-06-30 21:41:35 +02:00
committed by Christoffer Lerno
parent fad87b294b
commit 59a1590955
4 changed files with 18 additions and 4 deletions

View File

@@ -9,6 +9,7 @@
### Fixes
- mkdir/rmdir would not work properly with substring paths on non-windows platforms.
- Hex string formatter check incorrectly rejected slices.
### Stdlib changes

View File

@@ -3164,10 +3164,10 @@ static inline Type *type_flatten_no_export(Type *type)
}
}
static inline bool type_flat_is_char_array(Type *type)
static inline bool type_flat_is_char_array_slice(Type *type)
{
type = type_flatten(type);
if (type->type_kind != TYPE_ARRAY) return false;
if (type->type_kind != TYPE_ARRAY && type->type_kind != TYPE_SLICE) return false;
switch (type->array.base->type_kind)
{
case TYPE_I8:
@@ -3178,6 +3178,7 @@ static inline bool type_flat_is_char_array(Type *type)
}
}
INLINE Type *type_vector_type(Type *type)
{
Type *flatten = type_flatten(type);

View File

@@ -2081,9 +2081,9 @@ NEXT_FLAG:
goto NEXT;
case 'H':
case 'h':
if (!type_flat_is_char_array(type))
if (!type_flat_is_char_array_slice(type))
{
RETURN_SEMA_ERROR(vaargs[idx], "Expected a char array here.");
RETURN_SEMA_ERROR(vaargs[idx], "Expected a char array or slice here.");
}
goto NEXT;
default:

View File

@@ -0,0 +1,12 @@
import std::io;
macro convert_string_to_hex(String s)
{
io::printfn("%02hx", (char[])s);
}
fn void main() {
char[3] x = x"0305ff";
io::printfn("%02h", x);
convert_string_to_hex("colors");
}