From 3883c34b8c9943c44c9d19a8789e3e5e46d0946f Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Thu, 30 Jul 2020 12:04:55 +0300 Subject: [PATCH] vfmt: fix eating of `n` in `string(x,n)` --- vlib/v/fmt/fmt.v | 4 +++ vlib/v/fmt/tests/to_string_2_forms_keep.vv | 33 ++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 vlib/v/fmt/tests/to_string_2_forms_keep.vv diff --git a/vlib/v/fmt/fmt.v b/vlib/v/fmt/fmt.v index e166dcaf7a..73c43c208c 100644 --- a/vlib/v/fmt/fmt.v +++ b/vlib/v/fmt/fmt.v @@ -788,6 +788,10 @@ pub fn (mut f Fmt) expr(node ast.Expr) { node.typname = f.table.get_type_symbol(node.typ).name f.write(f.type_to_str(node.typ) + '(') f.expr(node.expr) + if node.has_arg { + f.write(', ') + f.expr(node.arg) + } f.write(')') } ast.CallExpr { diff --git a/vlib/v/fmt/tests/to_string_2_forms_keep.vv b/vlib/v/fmt/tests/to_string_2_forms_keep.vv new file mode 100644 index 0000000000..6a0cbfddde --- /dev/null +++ b/vlib/v/fmt/tests/to_string_2_forms_keep.vv @@ -0,0 +1,33 @@ +fn abc() string { + unsafe { + mut fullpath := vcalloc(4) + fullpath[0] = `a` + fullpath[1] = `b` + fullpath[2] = `c` + fullpath[3] = 0 + return string(fullpath) + } + return '' +} + +fn def() string { + unsafe { + mut fullpath := vcalloc(4) + fullpath[0] = `a` + fullpath[1] = `b` + fullpath[2] = `c` + fullpath[3] = 0 + return string(fullpath, 3) + } + return '' +} + +fn main() { + assert 'abc' == abc() + assert 'abc' == def() + abc_str1 := ptr_str(abc().str) + abc_str2 := ptr_str(abc().str) + println('abc_str1: $abc_str1') + println('abc_str2: $abc_str2') + assert abc_str1 != abc_str2 +}