diff --git a/vlib/v/parser/fn.v b/vlib/v/parser/fn.v index a3b7ae19133e95..1e8754f4af0055 100644 --- a/vlib/v/parser/fn.v +++ b/vlib/v/parser/fn.v @@ -1198,7 +1198,10 @@ fn (mut p Parser) check_fn_mutable_arguments(typ ast.Type, pos token.Pos) { } fn (mut p Parser) check_fn_shared_arguments(typ ast.Type, pos token.Pos) { - sym := p.table.sym(typ) + mut sym := p.table.sym(typ) + if sym.kind == .generic_inst { + sym = p.table.type_symbols[(sym.info as ast.GenericInst).parent_idx] + } if sym.kind !in [.array, .struct_, .map, .placeholder] && !typ.is_ptr() { p.error_with_pos('shared arguments are only allowed for arrays, maps, and structs\n', pos) diff --git a/vlib/v/tests/shared_generic_test.v b/vlib/v/tests/shared_generic_test.v index cdef7b87da3819..1a3ede83675451 100644 --- a/vlib/v/tests/shared_generic_test.v +++ b/vlib/v/tests/shared_generic_test.v @@ -12,3 +12,14 @@ fn test_shared_struct_has_generics() { assert bar.a == 1 } } + +fn generic_struct_as_parameters(shared arg Foo[int]) { + rlock arg { + assert arg.a == 1 + } +} + +fn test_generic_struct_as_parameters() { + shared foo := Foo[int]{1} + generic_struct_as_parameters(shared foo) +}