From b5d8c53a0c58abeccbaa903e6d9ecffd5c29b48c Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Sun, 19 Sep 2021 05:03:31 +0300 Subject: [PATCH] v.gen.c: fix the :X string interpolation format for isize/usize on 64bit systems --- vlib/v/gen/c/str_intp.v | 2 ++ vlib/v/tests/integer_size_test.v | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/vlib/v/gen/c/str_intp.v b/vlib/v/gen/c/str_intp.v index a3daef03bb..bcc3bf9106 100644 --- a/vlib/v/gen/c/str_intp.v +++ b/vlib/v/gen/c/str_intp.v @@ -91,6 +91,8 @@ fn (mut g Gen) str_format(node ast.StringInterLiteral, i int) (u64, string) { ast.i64_type { fmt_type = .si_i64 } ast.u64_type { fmt_type = .si_u64 } ast.u32_type { fmt_type = .si_u32 } + ast.usize_type { fmt_type = .si_u64 } + ast.isize_type { fmt_type = .si_i64 } else { fmt_type = .si_i32 } } } diff --git a/vlib/v/tests/integer_size_test.v b/vlib/v/tests/integer_size_test.v index 43b1a9c500..6794e11cbc 100644 --- a/vlib/v/tests/integer_size_test.v +++ b/vlib/v/tests/integer_size_test.v @@ -9,6 +9,9 @@ fn test_usize() { u++ assert u == 5 assert u.str() == '5' + $if x64 { + assert '${usize(0x140000000):X}' == '140000000' + } } fn test_isize() { @@ -19,4 +22,7 @@ fn test_isize() { i += 2 assert i == -3 assert i.str() == '-3' + $if x64 { + assert '${isize(0x140000000):X}' == '140000000' + } }