From f80876497e2135edbdcdca7bac0fb2cd171c8885 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Wed, 6 May 2020 12:43:46 +0200 Subject: [PATCH] fmt: use the new `mut` syntax in args --- vlib/v/ast/str.v | 5 ++++- vlib/v/fmt/tests/functions_expected.vv | 4 ++++ vlib/v/fmt/tests/functions_input.vv | 4 ++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/vlib/v/ast/str.v b/vlib/v/ast/str.v index 76bbb64ad8..92915f44cf 100644 --- a/vlib/v/ast/str.v +++ b/vlib/v/ast/str.v @@ -50,10 +50,13 @@ pub fn (node &FnDecl) str(t &table.Table) string { is_last_arg := i == node.args.len - 1 should_add_type := is_last_arg || node.args[i + 1].typ != arg.typ || (node.is_variadic && i == node.args.len - 2) + if arg.is_mut { + f.write('mut ') + } f.write(arg.name) mut s := t.type_to_str(arg.typ) if arg.is_mut { - f.write(' mut') + // f.write(' mut') if s.starts_with('&') { s = s[1..] } diff --git a/vlib/v/fmt/tests/functions_expected.vv b/vlib/v/fmt/tests/functions_expected.vv index c1158014af..eac39ec9ba 100644 --- a/vlib/v/fmt/tests/functions_expected.vv +++ b/vlib/v/fmt/tests/functions_expected.vv @@ -54,6 +54,10 @@ fn (f Foo) fn_with_optional() ?int { return 40 } +fn mut_array(mut a []int) { + println(1) +} + fn fn_with_ref_return() &Foo { return &Foo{} } diff --git a/vlib/v/fmt/tests/functions_input.vv b/vlib/v/fmt/tests/functions_input.vv index bf40337ba2..9498dcfecb 100644 --- a/vlib/v/fmt/tests/functions_input.vv +++ b/vlib/v/fmt/tests/functions_input.vv @@ -50,6 +50,10 @@ fn (f Foo) fn_with_optional() ?int { return 40 } +fn mut_array(a mut []int) { + println(1) +} + fn fn_with_ref_return() &Foo { return &Foo{} }