You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A [N]T (fixed-size array) cannot be passed to a generic function that takes []T — V refuses to infer the inner element type, even though the relationship is mechanical ([N]T and []T share the element type).
This forces every generic decoder/encoder that wants a single code path for both array kinds to either copy via a sibling dynamic array (slow) or manually rewrite the dynamic-array header to alias the fixed-array storage (unsafe).
Reproduction Steps
fnfill[T](mut arr []T) {
arr << T{}
}
fnfill_any[T](mut val T) {
$if T is $array_fixed {
fill(mut val)
}
}
fnmain() {
mutfixed:= [3]int{}
fill_any(mut fixed)
println(fixed)
}
Expected Behavior
Compiles. The checker infers T = int from [3]int matching []T.
Current Behavior
error: could not infer generic type`T`in call to `fill`
10 | fill(mut val)
|~~~~~~~~~~~~~
Possible Solution
When inferring T for an mut []T parameter and the call-site argument has type [N]E, accept the inference T = E. The runtime can either coerce the fixed array into a []T view (length and cap = N, data = &fixed[0]) or generate a small adapter that copies in/out at the call boundary.
Describe the bug
A
[N]T(fixed-size array) cannot be passed to a generic function that takes[]T— V refuses to infer the inner element type, even though the relationship is mechanical ([N]Tand[]Tshare the element type).This forces every generic decoder/encoder that wants a single code path for both array kinds to either copy via a sibling dynamic array (slow) or manually rewrite the dynamic-array header to alias the fixed-array storage (unsafe).
Reproduction Steps
Expected Behavior
Compiles. The checker infers
T = intfrom[3]intmatching[]T.Current Behavior
Possible Solution
When inferring
Tfor anmut []Tparameter and the call-site argument has type[N]E, accept the inferenceT = E. The runtime can either coerce the fixed array into a[]Tview (length and cap = N, data = &fixed[0]) or generate a small adapter that copies in/out at the call boundary.V version
V 0.5.1 (40b3711)
Environment details (OS name and version, etc.)
Note
You can use the 👍 reaction to increase the issue's priority for developers.
Please note that only the 👍 reaction to the issue itself counts as a vote.
Other reactions and those to comments will not be taken into account.