Skip to content

Commit

Permalink
parser: fix shared generic struct as fn parameters (fix #19804) (#19805)
Browse files Browse the repository at this point in the history
  • Loading branch information
shove70 committed Nov 8, 2023
1 parent b1ed652 commit b111a82
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
5 changes: 4 additions & 1 deletion vlib/v/parser/fn.v
Expand Up @@ -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)
Expand Down
11 changes: 11 additions & 0 deletions vlib/v/tests/shared_generic_test.v
Expand Up @@ -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)
}

0 comments on commit b111a82

Please sign in to comment.