Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

checker: disallow printing variadic values #19503

Merged
merged 1 commit into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions vlib/v/checker/fn.v
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,8 @@ fn (mut c Checker) builtin_args(mut node ast.CallExpr, fn_name string, func ast.
} else if arg.typ == ast.char_type && arg.typ.nr_muls() == 0 {
c.error('`${fn_name}` cannot print type `char` directly, print its address or cast it to an integer instead',
node.pos)
} else if arg.expr is ast.ArrayDecompose {
c.error('`${fn_name}` cannot print variadic values', node.pos)
spytheman marked this conversation as resolved.
Show resolved Hide resolved
}
c.fail_if_unreadable(arg.expr, arg.typ, 'argument to print')
c.inside_casting_to_str = false
Expand Down
4 changes: 4 additions & 0 deletions vlib/v/checker/tests/variadic_value_print_err.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
vlib/v/checker/tests/variadic_value_print_err.vv:2:1: error: `println` cannot print variadic values
1 | a := [1, 2, 3]
2 | println(...a)
| ~~~~~~~~~~~~~
2 changes: 2 additions & 0 deletions vlib/v/checker/tests/variadic_value_print_err.vv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
a := [1, 2, 3]
println(...a)