1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

vdoc: show variadic args correctly

This commit is contained in:
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

View File

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