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 +}