fmt: use the new `mut` syntax in args

pull/4752/head
Alexander Medvednikov 2020-05-06 12:43:46 +02:00
parent b4c93349e8
commit f80876497e
3 changed files with 12 additions and 1 deletions

View File

@ -50,10 +50,13 @@ pub fn (node &FnDecl) str(t &table.Table) string {
is_last_arg := i == node.args.len - 1 is_last_arg := i == node.args.len - 1
should_add_type := is_last_arg || node.args[i + 1].typ != arg.typ || (node.is_variadic && should_add_type := is_last_arg || node.args[i + 1].typ != arg.typ || (node.is_variadic &&
i == node.args.len - 2) i == node.args.len - 2)
if arg.is_mut {
f.write('mut ')
}
f.write(arg.name) f.write(arg.name)
mut s := t.type_to_str(arg.typ) mut s := t.type_to_str(arg.typ)
if arg.is_mut { if arg.is_mut {
f.write(' mut') // f.write(' mut')
if s.starts_with('&') { if s.starts_with('&') {
s = s[1..] s = s[1..]
} }

View File

@ -54,6 +54,10 @@ fn (f Foo) fn_with_optional() ?int {
return 40 return 40
} }
fn mut_array(mut a []int) {
println(1)
}
fn fn_with_ref_return() &Foo { fn fn_with_ref_return() &Foo {
return &Foo{} return &Foo{}
} }

View File

@ -50,6 +50,10 @@ fn (f Foo) fn_with_optional() ?int {
return 40 return 40
} }
fn mut_array(a mut []int) {
println(1)
}
fn fn_with_ref_return() &Foo { fn fn_with_ref_return() &Foo {
return &Foo{} return &Foo{}
} }