Array initializers init<S>(S) and init(repeating: Array.Element, count: Int) don’t seem to be implemented:
Array(array[0 ... 3]) gives ‘Parameter should be labeled “of”’
[Int](0..<256) gives ‘No overloaded constructor with these parameters for type “Array<Int64!>”, best matching overload is “init(_ sequence: INSFastEnumeration) -> Array<Int64!>!”’, which in turn results in ‘parameter 1 is “Range” should be “INSFastEnumeration”’
@mh, did you find out what is causing this? It still doesn’t work in Elements 10.0.0.2351. I just set out to implement all the parts I’m missing in SwiftBaseLibrary (including Array.contains), but they are all there. They just don’t work for some reason.
Ok, it does look like we have a couple compiler bugs here, what I can reproduce on .NET is:
let x = Array(array[0 ... 3]) // E122 Cannot instantiate abstract class "Array!"
(different/odd error, but definitively wrong)
let z = [UInt8](repeating: 0, count: 5) // E317 No overloaded constructor with these parameters for type "Array<UInt8>"
that one’s also wrong, as the .ctor is there.
I’ll log these two as compiler bugs.
as for the ranges, there are two issues, for one, the name-less .ctor that takes a sequence was not implemented for .NET (fixed); for another, Range does jot current;y implement the ISequence protocol, so it’s not directly compatible with that. I’ll fix this (needs some more work than I can do right this second), but this workaround works:
let s: ISequence<Int64> = (0..<256).GetSequence()
let y1 = [Int](s)
let x = Array(array[0 ... 3]) // E46 Unknown identifier "array"
kinda m makes sense now that I look at that closer. what’s that syntax supposed to be, array[0 ... 3]? this one works, instead:
let x = Array(array: [0 ... 3])
The other one
let z = [UInt8](repeating: 0, count: 5) // E317 No overloaded constructor with these parameters for type "Array<UInt8>" // E317 No overloaded constructor with these parameters for type "Swift.Array<Byte!>"
let array = [UInt8]()
let x1 = Array(array[0 ... 3]) // E599 Parameter labels do not match. Parameter 1 is unlabeled, but should should be labeled "contentsOfURL" in call to "init(contentsOfURL url: NSURL) -> NSArray<id!>!"
let x2 = Array(array: [0 ... 3])
which seems correct (ignoring that it suggests the wrong overloaded .ctor). the parameter is named, array: should be needed?
(Array does not have a constructor with named parameter array.) In any case, [0 ... 3] and array[0 ... 3] are sequences, so Array(sequence:) should work in Silver. Swift Base Library also has a convenience init without the prefix, but that doesn’t work yet.
The problem is arrays aren’t sequences on Cocoa, since we concerted the Array class to be a struct (on popular request), and structs cannot implement protocols (right now), that’s a platform limitation on Cocoa.
What I’ll do for now is add a name-less .ctor that takes arrays.
In Apple’s implementation, neither [0 ... 3] nor array[0 ... 3] is an array. The former is a ClosedRange and the latter is an ArraySlice, both of which are sequences.