Skip to content

Commit

Permalink
fix int formatting in std::collections::object
Browse files Browse the repository at this point in the history
  • Loading branch information
Renerick authored and lerno committed Oct 5, 2024
1 parent 2ef1465 commit 217151b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/std/collections/object.c3
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ fn usz! Object.to_format(&self, Formatter* formatter) @dynamic
switch (self.type.kindof)
{
case SIGNED_INT:
return formatter.printf("%d", self.i)!;
return formatter.printf("%d", (int128)self.i)!;
case UNSIGNED_INT:
return formatter.printf("%d", (uint128)self.i)!;
case FLOAT:
Expand Down
18 changes: 18 additions & 0 deletions test/unit/stdlib/collections/object.c3
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,21 @@ fn void test_general()
root.set("yyy", true);
assert(root.get_bool("yyy") ?? false);
}

fn void test_to_format_int()
{
{
Object* int_object = object::new_int(16, allocator::heap());
defer int_object.free();
String s = string::new_format("%s", int_object);
defer free(s);
assert(s == "16");
}
{
Object* int_object = object::new_int(-16, allocator::heap());
defer int_object.free();
String s = string::new_format("%s", int_object);
defer free(s);
assert(s == "-16");
}
}

0 comments on commit 217151b

Please sign in to comment.