Skip to content

Commit dd7f3a7

Browse files
authored
checker: disallow printing variadic expansions of arrays: print(...a), println(...a), where a is an array (fix #19490) (#19503)
1 parent c79f84d commit dd7f3a7

File tree

3 files changed

+8
-0
lines changed

3 files changed

+8
-0
lines changed

vlib/v/checker/fn.v

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,8 @@ fn (mut c Checker) builtin_args(mut node ast.CallExpr, fn_name string, func ast.
580580
} else if arg.typ == ast.char_type && arg.typ.nr_muls() == 0 {
581581
c.error('`${fn_name}` cannot print type `char` directly, print its address or cast it to an integer instead',
582582
node.pos)
583+
} else if arg.expr is ast.ArrayDecompose {
584+
c.error('`${fn_name}` cannot print variadic values', node.pos)
583585
}
584586
c.fail_if_unreadable(arg.expr, arg.typ, 'argument to print')
585587
c.inside_casting_to_str = false
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
vlib/v/checker/tests/variadic_value_print_err.vv:2:1: error: `println` cannot print variadic values
2+
1 | a := [1, 2, 3]
3+
2 | println(...a)
4+
| ~~~~~~~~~~~~~
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
a := [1, 2, 3]
2+
println(...a)

0 commit comments

Comments
 (0)