mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: check generics struct field type error (#15593)
This commit is contained in:
parent
9703410391
commit
e355ae7b3c
@ -74,6 +74,11 @@ pub fn (mut c Checker) struct_decl(mut node ast.StructDecl) {
|
||||
if info.is_heap && !field.typ.is_ptr() {
|
||||
struct_sym.info.is_heap = true
|
||||
}
|
||||
if info.generic_types.len > 0 && !field.typ.has_flag(.generic)
|
||||
&& info.concrete_types.len == 0 {
|
||||
c.error('field `$field.name` type is generic struct, must specify the generic type names, e.g. Foo<T>, Foo<int>',
|
||||
field.type_pos)
|
||||
}
|
||||
}
|
||||
if sym.kind == .multi_return {
|
||||
c.error('cannot use multi return as field type', field.type_pos)
|
||||
|
7
vlib/v/checker/tests/generics_struct_field_type_err.out
Normal file
7
vlib/v/checker/tests/generics_struct_field_type_err.out
Normal file
@ -0,0 +1,7 @@
|
||||
vlib/v/checker/tests/generics_struct_field_type_err.vv:4:9: error: field `next` type is generic struct, must specify the generic type names, e.g. Foo<T>, Foo<int>
|
||||
2 | mut:
|
||||
3 | value T
|
||||
4 | next &LL = unsafe { 0 }
|
||||
| ~~
|
||||
5 | }
|
||||
6 |
|
11
vlib/v/checker/tests/generics_struct_field_type_err.vv
Normal file
11
vlib/v/checker/tests/generics_struct_field_type_err.vv
Normal file
@ -0,0 +1,11 @@
|
||||
struct LL<T> {
|
||||
mut:
|
||||
value T
|
||||
next &LL = unsafe { 0 }
|
||||
}
|
||||
|
||||
fn main() {
|
||||
mut l := LL<int>{}
|
||||
l.value = 5
|
||||
println(l.value)
|
||||
}
|
Loading…
Reference in New Issue
Block a user