checker: add error for `print( voidfn() )`
parent
62ccd740f0
commit
d0e8e8f178
|
@ -1901,6 +1901,9 @@ pub fn (mut c Checker) call_fn(mut call_expr ast.CallExpr) table.Type {
|
||||||
c.inside_println_arg = true
|
c.inside_println_arg = true
|
||||||
c.expected_type = table.string_type
|
c.expected_type = table.string_type
|
||||||
call_expr.args[0].typ = c.expr(call_expr.args[0].expr)
|
call_expr.args[0].typ = c.expr(call_expr.args[0].expr)
|
||||||
|
if call_expr.args[0].typ.is_void() {
|
||||||
|
c.error('`$fn_name` can not print void expressions', call_expr.pos)
|
||||||
|
}
|
||||||
if call_expr.args[0].typ.has_flag(.shared_f) {
|
if call_expr.args[0].typ.has_flag(.shared_f) {
|
||||||
c.fail_if_not_rlocked(call_expr.args[0].expr, 'argument to print')
|
c.fail_if_not_rlocked(call_expr.args[0].expr, 'argument to print')
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,3 +4,10 @@ vlib/v/checker/tests/for_in_index_type.vv:2:11: error: for in: cannot index `int
|
||||||
| ~~
|
| ~~
|
||||||
3 | println(a)
|
3 | println(a)
|
||||||
4 | }
|
4 | }
|
||||||
|
vlib/v/checker/tests/for_in_index_type.vv:3:3: error: `println` can not print void expressions
|
||||||
|
1 | fn main() {
|
||||||
|
2 | for a in 52 {
|
||||||
|
3 | println(a)
|
||||||
|
| ~~~~~~~~~~
|
||||||
|
4 | }
|
||||||
|
5 | }
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
vlib/v/checker/tests/println_can_not_print_void_expressions.vv:3:2: error: `print` can not print void expressions
|
||||||
|
1 | fn blabla() {}
|
||||||
|
2 | fn main() {
|
||||||
|
3 | print(blabla())
|
||||||
|
| ~~~~~~~~~~~~~~~
|
||||||
|
4 | println(blabla())
|
||||||
|
5 | eprint(blabla())
|
||||||
|
vlib/v/checker/tests/println_can_not_print_void_expressions.vv:4:2: error: `println` can not print void expressions
|
||||||
|
2 | fn main() {
|
||||||
|
3 | print(blabla())
|
||||||
|
4 | println(blabla())
|
||||||
|
| ~~~~~~~~~~~~~~~~~
|
||||||
|
5 | eprint(blabla())
|
||||||
|
6 | eprintln(blabla())
|
||||||
|
vlib/v/checker/tests/println_can_not_print_void_expressions.vv:5:2: error: `eprint` can not print void expressions
|
||||||
|
3 | print(blabla())
|
||||||
|
4 | println(blabla())
|
||||||
|
5 | eprint(blabla())
|
||||||
|
| ~~~~~~~~~~~~~~~~
|
||||||
|
6 | eprintln(blabla())
|
||||||
|
7 | }
|
||||||
|
vlib/v/checker/tests/println_can_not_print_void_expressions.vv:6:2: error: `eprintln` can not print void expressions
|
||||||
|
4 | println(blabla())
|
||||||
|
5 | eprint(blabla())
|
||||||
|
6 | eprintln(blabla())
|
||||||
|
| ~~~~~~~~~~~~~~~~~~
|
||||||
|
7 | }
|
|
@ -0,0 +1,7 @@
|
||||||
|
fn blabla() {}
|
||||||
|
fn main() {
|
||||||
|
print(blabla())
|
||||||
|
println(blabla())
|
||||||
|
eprint(blabla())
|
||||||
|
eprintln(blabla())
|
||||||
|
}
|
Loading…
Reference in New Issue