Skip to content

Commit

Permalink
parser: fix generic fn call with fixed array argument
Browse files Browse the repository at this point in the history
  • Loading branch information
yuyi98 committed Nov 14, 2023
1 parent 55cac88 commit b6b9126
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
4 changes: 2 additions & 2 deletions vlib/v/parser/parser.v
Original file line number Diff line number Diff line change
Expand Up @@ -2416,8 +2416,8 @@ fn (p &Parser) is_generic_call() bool {
}

if kind2 == .lsbr {
// case 1
return tok3.kind == .rsbr
// case 1 (array or fixed array type)
return tok3.kind == .rsbr || (tok4.kind == .rsbr && p.is_typename(tok5))
}

if kind2 == .name {
Expand Down
21 changes: 21 additions & 0 deletions vlib/v/tests/generics_call_with_fixed_array_arg_test.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
fn generic[T](t T) string {
return '${t}'
}

fn test_generic_call_with_fixed_array_arg() {
r1 := generic[[3]int]([1, 2, 3]!)
println(r1)
assert r1 == '[1, 2, 3]'

r2 := generic[[]int]([1, 2, 3])
println(r2)
assert r2 == '[1, 2, 3]'

r3 := generic[int](22)
println(r3)
assert r3 == '22'

r4 := generic[bool](true)
println(r4)
assert r4 == 'true'
}

0 comments on commit b6b9126

Please sign in to comment.