From ef643e106b50d7f924b5172670dda262d5355d72 Mon Sep 17 00:00:00 2001 From: yuyi Date: Sat, 25 Jun 2022 10:19:41 +0800 Subject: [PATCH] checker: check unknown chan element type (#14843) --- vlib/v/checker/checker.v | 6 ++++++ vlib/v/checker/tests/chan_elem_type_unknown.out | 5 +++++ vlib/v/checker/tests/chan_elem_type_unknown.vv | 3 +++ 3 files changed, 14 insertions(+) create mode 100644 vlib/v/checker/tests/chan_elem_type_unknown.out create mode 100644 vlib/v/checker/tests/chan_elem_type_unknown.vv diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index 33556a2e71..72e9d53798 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -3523,6 +3523,12 @@ pub fn (mut c Checker) chan_init(mut node ast.ChanInit) ast.Type { if node.typ != 0 { info := c.table.sym(node.typ).chan_info() node.elem_type = info.elem_type + if node.elem_type != 0 { + elem_sym := c.table.sym(node.elem_type) + if elem_sym.kind == .placeholder { + c.error('unknown type `$elem_sym.name`', node.pos) + } + } if node.has_cap { c.check_array_init_para_type('cap', node.cap_expr, node.pos) } diff --git a/vlib/v/checker/tests/chan_elem_type_unknown.out b/vlib/v/checker/tests/chan_elem_type_unknown.out new file mode 100644 index 0000000000..5fa982abab --- /dev/null +++ b/vlib/v/checker/tests/chan_elem_type_unknown.out @@ -0,0 +1,5 @@ +vlib/v/checker/tests/chan_elem_type_unknown.vv:2:7: error: unknown type `NonExistingType` + 1 | fn main() { + 2 | _ := chan NonExistingType{} + | ~~~~~~~~~~~~~~~~~~~~~~ + 3 | } diff --git a/vlib/v/checker/tests/chan_elem_type_unknown.vv b/vlib/v/checker/tests/chan_elem_type_unknown.vv new file mode 100644 index 0000000000..4ad22b0e3d --- /dev/null +++ b/vlib/v/checker/tests/chan_elem_type_unknown.vv @@ -0,0 +1,3 @@ +fn main() { + _ := chan NonExistingType{} +}