let x: Int? = 1
let y: Int? = 2
let z = y as? Int // ⚠️ Conditional downcast from 'Int?' to 'Int' does nothing
In the version of your example that produces no warning:
let a: [Int]? = xy as? [Int]
there are two "layers" of casting: one layer of per-element casts (similar to a compactMap as you've noted) to try to convert the values from Int? to Int, and a second cast to try to convert the result to [Int], depending on the result of the first layer.
In the original version:
let a: [Int]? = [x, y] as? [Int]
I think there are three layers of casting: an initial attempt to cast the expression result type of [x, y] to [Int] by type inference on the array elements — which doesn't succeed in getting Ints so the result is [Int?], but produces the warning — then the other two layers. The warning occurs in that extra "layer", so it only appears in this version.
Ah, that must be (at least part of) the explanation. It's unfortunate that it results in this kind of confusing behavior. I guess the issue with the nonsensical warning might somehow be caused by this as well.
[Int?] and [Int] are quite different types.. (I believe internally there'll be 9 (or 10?) bytes per element for the former and only 8 for the latter (on 64 bit platforms).
The cast above is not redundant, it converts from [Int?] to [Int], converting every element of array from Int? to Int (if it can), doing this in O(n) time, and if it can't (i.e. when one of the elements is nil) it returns nil. That's what as? is doing. I believe you'll get the same result using:
([x, y] as [Int?]) as! [Int]?
in other way as? [Int] and as! [Int]? should be equivalent.
(the difference is that if for array of, say, strings, as? [Int] would produce nil and as! [Int]? would crash.)