Skip to content

Commit 1340a47

Browse files
committed
- any_to_int checks value to be int and no longer works with enum.
- Add check in formatter printing "%c".
1 parent 4f4476b commit 1340a47

File tree

4 files changed

+19
-7
lines changed

4 files changed

+19
-7
lines changed

lib/std/core/types.c3

+12-6
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,24 @@ fault ConversionResult
88
VALUE_OUT_OF_RANGE,
99
VALUE_OUT_OF_UNSIGNED_RANGE,
1010
}
11+
12+
<*
13+
@require $Type.kindof.is_int() "Type was not an integer"
14+
@require v.type.kindof == ENUM "Value was not an enum"
15+
*>
16+
macro any_to_enum_ordinal(any v, $Type)
17+
{
18+
return any_to_int(v.as_inner(), $Type);
19+
}
20+
1121
<*
12-
@require $Type.kindof.is_int() || $Type.kindof == TypeKind.ENUM "Argument was not an integer"
22+
@require $Type.kindof.is_int() "Type was not an integer"
23+
@require v.type.kindof.is_int() "Value was not an integer"
1324
*>
1425
macro any_to_int(any v, $Type)
1526
{
1627
typeid any_type = v.type;
1728
TypeKind kind = any_type.kindof;
18-
if (kind == TypeKind.ENUM)
19-
{
20-
any_type = any_type.inner;
21-
kind = any_type.kindof;
22-
}
2329
bool is_mixed_signed = $Type.kindof != any_type.kindof;
2430
$Type max = $Type.max;
2531
$Type min = $Type.min;

lib/std/io/formatter.c3

+1-1
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ fn usz! Formatter.out_str(&self, any arg) @private
195195
switch (arg.type.kindof)
196196
{
197197
case ENUM:
198-
usz i = types::any_to_int(arg, usz)!!;
198+
usz i = types::any_to_enum_ordinal(arg, usz)!!;
199199
assert(i < arg.type.names.len, "Illegal enum value found, numerical value was %d.", i);
200200
return self.out_substr(arg.type.names[i]);
201201
case STRUCT:

lib/std/io/formatter_private.c3

+4
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,10 @@ fn usz! Formatter.ntoa_any(&self, any arg, uint base) @private
606606

607607
fn usz! Formatter.out_char(&self, any arg) @private
608608
{
609+
if (!arg.type.kindof.is_int())
610+
{
611+
return self.out_substr("<NOT CHAR>");
612+
}
609613
usz len = 1;
610614
uint l = 1;
611615
// pre padding

releasenotes.md

+2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
- Fix crash on project.json not having an empty set of targets.
3232
- Miscompile when indexing an array with small unsigned types for enums.
3333
- Change CBool to be 1 byte.
34+
- `any_to_int` checks value to be int and no longer works with enum.
35+
- Add check in formatter printing "%c".
3436

3537
### Stdlib changes
3638
- Increase BitWriter.write_bits limit up to 32 bits.

0 commit comments

Comments
 (0)