checker: check for an unknown struct name (fix #8007) (#8010)

pull/8016/head
yuyi 2021-01-11 03:16:53 +08:00 committed by GitHub
parent 692a718428
commit a97ed55a09
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 0 deletions

View File

@ -511,6 +511,9 @@ pub fn (mut c Checker) struct_init(mut struct_init ast.StructInit) table.Type {
struct_init.pos)
}
}
if type_sym.name.len == 1 && !c.cur_fn.is_generic {
c.error('unknown struct `$type_sym.name`', struct_init.pos)
}
match type_sym.kind {
.placeholder {
c.error('unknown struct: $type_sym.name', struct_init.pos)

View File

@ -0,0 +1,6 @@
vlib/v/checker/tests/unknown_struct_name.vv:4:7: error: unknown struct `F`
2 |
3 | fn main() {
4 | _ := F{}
| ~~~
5 | }

View File

@ -0,0 +1,5 @@
module main
fn main() {
_ := F{}
}