Variadic Parameters that Accept Array Inputs

How does this resolve the ambiguity of

func doAThing(with items: Any...) -> [Any] {
    return items
}

let res = doAThing(with: 1, 2, 3)
let res2 = doAThing(with: res)

Does the second call to doAThing receive three arguments (1, 2, 3, splatting res), or only one ([1, 2, 3], since res can be promoted to Any)? Or is this now a compilation error (which is potentially source-breaking)?

I've been bitten both ways in other languages which support argument splatting in this way; it'd be nice to offer a less ambiguous and surprising solution.

2 Likes