1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

checker: type inference over a generic type should compile (#13824)

This commit is contained in:
Vincenzo Palazzo
2022-04-01 18:31:27 +02:00
committed by GitHub
parent 9d2529b611
commit d7817863c6
5 changed files with 28 additions and 4 deletions

View File

@ -327,7 +327,9 @@ pub fn (mut rng PRNG) choose<T>(array []T, k int) ?[]T {
}
mut results := []T{len: k}
mut indices := []int{len: n, init: it}
rng.shuffle(mut indices) ?
// TODO: see why exactly it is necessary to enfoce the type here in Checker.infer_fn_generic_types
// (v errors with: `inferred generic type T is ambiguous: got int, expected string`, when <int> is missing)
rng.shuffle<int>(mut indices) ?
for i in 0 .. k {
results[i] = array[indices[i]]
}