I wasn't expecting the "Index out of bounds" error on combo2
.. maybe I should have been. Apparently combo2
is 'inheriting' the indices of array1
and since indices 0 and 1 of array1
were not included in combo2
, they don't exist there. Explicitly typing combo1
as [Int]
gives me the behavior I expected (at, I suspect, the cost of copying the array).
let array1 = [0,1,2,3,4]
let array2 = [9,8,7,6,5]
let combo1: [Int] = array1[2...] + array2
let combo2 = array1[2...] + array2
var wowee1 = combo1[3]
wowee1 = combo1[2] // = 4
wowee1 = combo1[1]
wowee1 = combo1[0]
var wowee2 = combo2[3]
wowee2 = combo2[2] // = 2
wowee2 = combo2[1] // Fatal error: Index out of bounds: file
// /AppleInternal/BuildRoot/Library/Caches/com.apple.xbs/Sources/
// swiftlang/swiftlang-1103.8.25.8/swift/stdlib/public/core/SliceBuffer.swift, line 290