1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

checker: check unknown chan element type (#14843)

This commit is contained in:
yuyi 2022-06-25 10:19:41 +08:00 committed by GitHub
parent 90287f6aaa
commit ef643e106b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 0 deletions

View File

@ -3523,6 +3523,12 @@ pub fn (mut c Checker) chan_init(mut node ast.ChanInit) ast.Type {
if node.typ != 0 { if node.typ != 0 {
info := c.table.sym(node.typ).chan_info() info := c.table.sym(node.typ).chan_info()
node.elem_type = info.elem_type 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 { if node.has_cap {
c.check_array_init_para_type('cap', node.cap_expr, node.pos) c.check_array_init_para_type('cap', node.cap_expr, node.pos)
} }

View File

@ -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 | }

View File

@ -0,0 +1,3 @@
fn main() {
_ := chan NonExistingType{}
}