mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: check struct field using 'any' type (#12489)
This commit is contained in:
parent
2eb02ff5a7
commit
1370516f53
@ -638,6 +638,9 @@ pub fn (mut c Checker) struct_decl(mut node ast.StructDecl) {
|
||||
}
|
||||
}
|
||||
for i, field in node.fields {
|
||||
if field.typ == ast.any_type {
|
||||
c.error('struct field cannot be the `any` type, use generics instead', field.type_pos)
|
||||
}
|
||||
c.ensure_type_exists(field.typ, field.type_pos) or { return }
|
||||
if field.typ.has_flag(.generic) {
|
||||
has_generic_types = true
|
||||
|
6
vlib/v/checker/tests/struct_field_with_any_type_err.out
Normal file
6
vlib/v/checker/tests/struct_field_with_any_type_err.out
Normal file
@ -0,0 +1,6 @@
|
||||
vlib/v/checker/tests/struct_field_with_any_type_err.vv:2:6: error: struct field cannot be the `any` type, use generics instead
|
||||
1 | struct My_type {
|
||||
2 | fld any
|
||||
| ~~~
|
||||
3 | }
|
||||
4 |
|
8
vlib/v/checker/tests/struct_field_with_any_type_err.vv
Normal file
8
vlib/v/checker/tests/struct_field_with_any_type_err.vv
Normal file
@ -0,0 +1,8 @@
|
||||
struct My_type {
|
||||
fld any
|
||||
}
|
||||
|
||||
fn main() {
|
||||
a := My_type{}
|
||||
println(a)
|
||||
}
|
Loading…
Reference in New Issue
Block a user