On May 16, 2016, at 10:09 AM, Joe Groff via swift-users <swift-users@swift.org> wrote: > >> The oddity is that if I change the assignment to this >> >> var y : [Int] = Array(a[0..<n]) >> >> then the compiler is happy. >> >> Shouldn’t it be able to do any necessary type inference from the fact that >> the expression is in a context where an array is required? > > The error message is misleading (if you have time, we'd appreciate a bug > report!). What's really going on is that a[0..<n] produces an ArraySlice<T>, > not an Array<T>, in order to share memory with the underlying array. The type > doesn't match in your assignment. If `x` is just temporary, I'd recommend > leaving the type annotation out, since `var x = a[0..<n]` should just work.
FWIW, master produces the error: test.swift:2:27: error: cannot subscript a value of type '[Int]' with an index of type 'CountableRange<Int>' var x : [Int] = a[0..<n] ^ test.swift:2:27: note: overloads for 'subscript' exist with these partially matching parameter lists: (Int), (Range<Int>), (Range<Self.Index>), (ClosedRange<Self.Index>), (CountableClosedRange<Self.Index>) var x : [Int] = a[0..<n] ^ -Chris _______________________________________________ swift-users mailing list swift-users@swift.org https://lists.swift.org/mailman/listinfo/swift-users