Skip to content

Commit

Permalink
checker: disallow printing variadic expansions of arrays: `print(...a…
Browse files Browse the repository at this point in the history
…)`, `println(...a)`, where a is an array (fix vlang#19490) (vlang#19503)
  • Loading branch information
Delta456 authored and Wertzui123 committed Oct 8, 2023
1 parent e864aa2 commit dc1232a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
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)
}
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)

0 comments on commit dc1232a

Please sign in to comment.