mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: check printing of optional type
This commit is contained in:
parent
cff2874608
commit
ed393896f5
@ -1017,6 +1017,10 @@ pub fn (mut c Checker) call_fn(mut call_expr ast.CallExpr) table.Type {
|
|||||||
if (fn_name == 'println' || fn_name == 'print') && call_expr.args.len > 0 {
|
if (fn_name == 'println' || fn_name == 'print') && call_expr.args.len > 0 {
|
||||||
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)
|
||||||
|
// check optional argument
|
||||||
|
if call_expr.args[0].typ.has_flag(.optional) {
|
||||||
|
c.error('cannot print optional type', call_expr.args[0].expr.position())
|
||||||
|
}
|
||||||
/*
|
/*
|
||||||
// TODO: optimize `struct T{} fn (t &T) str() string {return 'abc'} mut a := []&T{} a << &T{} println(a[0])`
|
// TODO: optimize `struct T{} fn (t &T) str() string {return 'abc'} mut a := []&T{} a << &T{} println(a[0])`
|
||||||
// It currently generates:
|
// It currently generates:
|
||||||
|
6
vlib/v/checker/tests/print_optional_type_err.out
Normal file
6
vlib/v/checker/tests/print_optional_type_err.out
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
vlib/v/checker/tests/print_optional_type_err.v:3:13: error: cannot print optional type
|
||||||
|
1 | import os
|
||||||
|
2 | fn main() {
|
||||||
|
3 | println(os.ls('.'))
|
||||||
|
| ~~~~~~~
|
||||||
|
4 | }
|
4
vlib/v/checker/tests/print_optional_type_err.vv
Normal file
4
vlib/v/checker/tests/print_optional_type_err.vv
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
import os
|
||||||
|
fn main() {
|
||||||
|
println(os.ls('.'))
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user