checker: check error for unknown type in anon fn field of struct (#13778)

pull/13782/head
yuyi 2022-03-20 19:28:35 +08:00 committed by GitHub
parent 8c3687aa10
commit 0a78847782
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 0 deletions

View File

@ -55,6 +55,16 @@ pub fn (mut c Checker) struct_decl(mut node ast.StructDecl) {
field.type_pos)
}
}
field_sym := c.table.sym(field.typ)
if field_sym.kind == .function {
fn_info := field_sym.info as ast.FnType
c.ensure_type_exists(fn_info.func.return_type, fn_info.func.return_type_pos) or {
return
}
for param in fn_info.func.params {
c.ensure_type_exists(param.typ, param.type_pos) or { return }
}
}
}
if sym.kind == .struct_ {
info := sym.info as ast.Struct

View File

@ -0,0 +1,7 @@
vlib/v/checker/tests/unknown_type_in_anon_fn.vv:5:10: error: unknown type `Another`
3 | struct Struc{
4 | mut:
5 | f fn (s Another, i int) ?
| ~~~~~~~
6 | }
7 |

View File

@ -0,0 +1,8 @@
module main
struct Struc{
mut:
f fn (s Another, i int) ?
}
fn main() {}