diff --git a/vlib/v/checker/struct.v b/vlib/v/checker/struct.v index b0e4d4e42b..576662eb3d 100644 --- a/vlib/v/checker/struct.v +++ b/vlib/v/checker/struct.v @@ -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 diff --git a/vlib/v/checker/tests/unknown_type_in_anon_fn.out b/vlib/v/checker/tests/unknown_type_in_anon_fn.out new file mode 100644 index 0000000000..2045ddbba6 --- /dev/null +++ b/vlib/v/checker/tests/unknown_type_in_anon_fn.out @@ -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 | diff --git a/vlib/v/checker/tests/unknown_type_in_anon_fn.vv b/vlib/v/checker/tests/unknown_type_in_anon_fn.vv new file mode 100644 index 0000000000..f03742cc4d --- /dev/null +++ b/vlib/v/checker/tests/unknown_type_in_anon_fn.vv @@ -0,0 +1,8 @@ +module main + +struct Struc{ +mut: + f fn (s Another, i int) ? +} + +fn main() {}