diff --git a/lib/std/core/types.c3 b/lib/std/core/types.c3 index 6b40b1145..cf6d9d6c1 100644 --- a/lib/std/core/types.c3 +++ b/lib/std/core/types.c3 @@ -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; diff --git a/lib/std/io/formatter.c3 b/lib/std/io/formatter.c3 index fe4f1c76d..31319decb 100644 --- a/lib/std/io/formatter.c3 +++ b/lib/std/io/formatter.c3 @@ -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: diff --git a/lib/std/io/formatter_private.c3 b/lib/std/io/formatter_private.c3 index 760eb4ff1..f57c6c29e 100644 --- a/lib/std/io/formatter_private.c3 +++ b/lib/std/io/formatter_private.c3 @@ -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(""); + } usz len = 1; uint l = 1; // pre padding diff --git a/releasenotes.md b/releasenotes.md index 2ef396494..fc75cf051 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -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.