From ba78c10b320591894c98c8c34869c7559cdf8dba Mon Sep 17 00:00:00 2001 From: Denis Palashevskii Date: Sat, 5 Oct 2024 13:17:18 +0400 Subject: [PATCH] fix int formatting in std::collections::object --- lib/std/collections/object.c3 | 2 +- test/unit/stdlib/collections/object.c3 | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/std/collections/object.c3 b/lib/std/collections/object.c3 index 12bfa1bbd..49a952370 100644 --- a/lib/std/collections/object.c3 +++ b/lib/std/collections/object.c3 @@ -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: diff --git a/test/unit/stdlib/collections/object.c3 b/test/unit/stdlib/collections/object.c3 index b9c8f0123..287f4bbf7 100644 --- a/test/unit/stdlib/collections/object.c3 +++ b/test/unit/stdlib/collections/object.c3 @@ -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"); + } +}