Skip to content

Commit

Permalink
parser: fix shared generic struct as fn parameters(fix vlang#19804)
Browse files Browse the repository at this point in the history
  • Loading branch information
shove70 committed Nov 7, 2023
1 parent e736eca commit 73b13a3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
6 changes: 5 additions & 1 deletion vlib/v/parser/fn.v
Original file line number Diff line number Diff line change
Expand Up @@ -1198,8 +1198,12 @@ 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() {
println(sym.info)
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
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,14 @@ fn test_shared_struct_has_generics() {
assert bar.a == 1
}
}

fn generic_ _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 73b13a3

Please sign in to comment.