Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
checker: disallow printing variadic expansions of arrays: `print(...a…
- Loading branch information
Showing
3 changed files
with
8 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
Delta456
Author
Member
|
||
} | ||
c.fail_if_unreadable(arg.expr, arg.typ, 'argument to print') | ||
c.inside_casting_to_str = false | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
| ~~~~~~~~~~~~~ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
a := [1, 2, 3] | ||
println(...a) |
Is this only for println()? What happens with other functions that expect an any parameter?