vdoc: show variadic args correctly

pull/3882/head
yuyi 2020-02-29 22:04:07 +08:00 committed by GitHub
parent ee0a0afb25
commit 6c85e285e7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 3 deletions

View File

@ -19,16 +19,22 @@ pub fn (node &FnDecl) str(t &table.Table) string {
sym := t.get_type_symbol(node.receiver.typ) sym := t.get_type_symbol(node.receiver.typ)
name := sym.name.after('.') name := sym.name.after('.')
m := if node.rec_mut { 'mut ' } else { '' } m := if node.rec_mut { 'mut ' } else { '' }
receiver = '($node.receiver.name ${m}$name) ' receiver = '($node.receiver.name $m$name) '
} }
name := node.name.after('.') name := node.name.after('.')
f.write('fn ${receiver}${name}(') f.write('fn ${receiver}${name}(')
for i, arg in node.args { for i, arg in node.args {
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 should_add_type := is_last_arg || node.args[i + 1].typ != arg.typ ||
(node.is_variadic && i == node.args.len - 2)
f.write(arg.name) f.write(arg.name)
if should_add_type { if should_add_type {
f.write(' ' + t.type_to_str(arg.typ)) if node.is_variadic && is_last_arg {
f.write(' ...' + t.type_to_str(arg.typ))
}
else {
f.write(' ' + t.type_to_str(arg.typ))
}
} }
if !is_last_arg { if !is_last_arg {
f.write(', ') f.write(', ')