mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: check error for unknown type in anon fn field of struct (#13778)
This commit is contained in:
parent
8c3687aa10
commit
0a78847782
@ -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
|
||||
|
7
vlib/v/checker/tests/unknown_type_in_anon_fn.out
Normal file
7
vlib/v/checker/tests/unknown_type_in_anon_fn.out
Normal 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 |
|
8
vlib/v/checker/tests/unknown_type_in_anon_fn.vv
Normal file
8
vlib/v/checker/tests/unknown_type_in_anon_fn.vv
Normal file
@ -0,0 +1,8 @@
|
||||
module main
|
||||
|
||||
struct Struc{
|
||||
mut:
|
||||
f fn (s Another, i int) ?
|
||||
}
|
||||
|
||||
fn main() {}
|
Loading…
Reference in New Issue
Block a user