coalesceVariadicValues returns a new value set that coalesces all variadic parameters into an array parameter
(returnValues []any)
| 180 | |
| 181 | // coalesceVariadicValues returns a new value set that coalesces all variadic parameters into an array parameter |
| 182 | func (o *Overload) coalesceVariadicValues(returnValues []any) []any { |
| 183 | // If the overload is not variadic, then we don't need to do anything |
| 184 | if o.variadic < 0 { |
| 185 | return returnValues |
| 186 | } |
| 187 | coalescedValues := make([]any, len(o.paramTypes)) |
| 188 | copy(coalescedValues, returnValues[:o.variadic]) |
| 189 | // This is for the values after the variadic index, so we need to add 1. We subtract the extended parameter count |
| 190 | // from the actual parameter count to obtain the additional parameter count. |
| 191 | firstValueAfterVariadic := o.variadic + 1 + (len(o.argTypes) - len(o.paramTypes)) |
| 192 | copy(coalescedValues[o.variadic+1:], returnValues[firstValueAfterVariadic:]) |
| 193 | // We can just take the relevant slice out of the given values to represent our array, since all arrays use []any |
| 194 | coalescedValues[o.variadic] = returnValues[o.variadic:firstValueAfterVariadic] |
| 195 | return coalescedValues |
| 196 | } |
| 197 | |
| 198 | // overloadMatch is the result of a successful overload resolution, containing the types of the parameters as well |
| 199 | // as the type cast functions required to convert every argument to its appropriate parameter type |