describe in more details, what happens without <int>, in the `rng.shuffle<int>(mut indices) ?` call

pull/13824/head
Delyan Angelov 2022-04-01 18:23:35 +03:00
parent 565c012554
commit e08d7769fc
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
1 changed files with 2 additions and 1 deletions

View File

@ -327,7 +327,8 @@ pub fn (mut rng PRNG) choose<T>(array []T, k int) ?[]T {
} }
mut results := []T{len: k} mut results := []T{len: k}
mut indices := []int{len: n, init: it} mut indices := []int{len: n, init: it}
// enfoce the type to int to avoid ambiguity // 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) ? rng.shuffle<int>(mut indices) ?
for i in 0 .. k { for i in 0 .. k {
results[i] = array[indices[i]] results[i] = array[indices[i]]