diff --git a/vlib/v/checker/struct.v b/vlib/v/checker/struct.v index e97571fde5..266fb40770 100644 --- a/vlib/v/checker/struct.v +++ b/vlib/v/checker/struct.v @@ -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, Foo', + field.type_pos) + } } if sym.kind == .multi_return { c.error('cannot use multi return as field type', field.type_pos) diff --git a/vlib/v/checker/tests/generics_struct_field_type_err.out b/vlib/v/checker/tests/generics_struct_field_type_err.out new file mode 100644 index 0000000000..4f844c4bd7 --- /dev/null +++ b/vlib/v/checker/tests/generics_struct_field_type_err.out @@ -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, Foo + 2 | mut: + 3 | value T + 4 | next &LL = unsafe { 0 } + | ~~ + 5 | } + 6 | diff --git a/vlib/v/checker/tests/generics_struct_field_type_err.vv b/vlib/v/checker/tests/generics_struct_field_type_err.vv new file mode 100644 index 0000000000..950faea0fb --- /dev/null +++ b/vlib/v/checker/tests/generics_struct_field_type_err.vv @@ -0,0 +1,11 @@ +struct LL { + mut: + value T + next &LL = unsafe { 0 } +} + +fn main() { + mut l := LL{} + l.value = 5 + println(l.value) +}