checker: check struct field using 'any' type (#12489)
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
|
||||
|
|
|
@ -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 |
|
|
@ -0,0 +1,8 @@
|
|||
struct My_type {
|
||||
fld any
|
||||
}
|
||||
|
||||
fn main() {
|
||||
a := My_type{}
|
||||
println(a)
|
||||
}
|
Loading…
Reference in New Issue