- any_to_int checks value to be int and no longer works with enum.

- Add check in formatter printing "%c".
This commit is contained in:
Christoffer Lerno
2024-12-29 17:06:53 +01:00
parent 4f4476ba75
commit 1340a47bc2
4 changed files with 19 additions and 7 deletions

View File

@@ -8,18 +8,24 @@ fault ConversionResult
VALUE_OUT_OF_RANGE,
VALUE_OUT_OF_UNSIGNED_RANGE,
}
<*
@require $Type.kindof.is_int() || $Type.kindof == TypeKind.ENUM "Argument was not an integer"
@require $Type.kindof.is_int() "Type was not an integer"
@require v.type.kindof == ENUM "Value was not an enum"
*>
macro any_to_enum_ordinal(any v, $Type)
{
return any_to_int(v.as_inner(), $Type);
}
<*
@require $Type.kindof.is_int() "Type was not an integer"
@require v.type.kindof.is_int() "Value was not an integer"
*>
macro any_to_int(any v, $Type)
{
typeid any_type = v.type;
TypeKind kind = any_type.kindof;
if (kind == TypeKind.ENUM)
{
any_type = any_type.inner;
kind = any_type.kindof;
}
bool is_mixed_signed = $Type.kindof != any_type.kindof;
$Type max = $Type.max;
$Type min = $Type.min;

View File

@@ -195,7 +195,7 @@ fn usz! Formatter.out_str(&self, any arg) @private
switch (arg.type.kindof)
{
case ENUM:
usz i = types::any_to_int(arg, usz)!!;
usz i = types::any_to_enum_ordinal(arg, usz)!!;
assert(i < arg.type.names.len, "Illegal enum value found, numerical value was %d.", i);
return self.out_substr(arg.type.names[i]);
case STRUCT:

View File

@@ -606,6 +606,10 @@ fn usz! Formatter.ntoa_any(&self, any arg, uint base) @private
fn usz! Formatter.out_char(&self, any arg) @private
{
if (!arg.type.kindof.is_int())
{
return self.out_substr("<NOT CHAR>");
}
usz len = 1;
uint l = 1;
// pre padding

View File

@@ -31,6 +31,8 @@
- Fix crash on project.json not having an empty set of targets.
- Miscompile when indexing an array with small unsigned types for enums.
- Change CBool to be 1 byte.
- `any_to_int` checks value to be int and no longer works with enum.
- Add check in formatter printing "%c".
### Stdlib changes
- Increase BitWriter.write_bits limit up to 32 bits.