Casting to Any does not work on Island

The following piece of code compiles fine on Toffee v1, but not on Island:

var data: [UInt8] = [0, 1, 2, 3, 4]
var nestedArray = [[Any]]()
nestedArray.append(data)  // Parameter 1 should be "Swift.Array<Any!>"
nestedArray[0].append(5)  // Property is read-only

(I did some additional testing, and the “Property is read-only” error does appear to be a separate issue.)

Arrays (and most non-variant generics) are not compatible between different types. If you have type A descending from B. you can assign an a to a variable of type B, but you cannot assign an array of A to an array of B. so that third line cannot work.

Is there a way to work around this? It does work in Toffee v1 and with Apple’s compiler.

Not sure. @ck?

We can add an overload that is a little more flexible in appending, but internally, a [[uint8]] is an Array<UInt8> and won’t really be compatible. @mh we should see if this is a feature of Swift generics or an overload.

IIRC, Apple-Swift originally only allowed such conversions in Arrays between class types in the same hierarchy + AnyObject, but when they switched the ObjC importer to import id as Any, people got annoyed, and so they eventually allowed it (almost) everywhere, despite it being an O(n) existential allocation cost.

I thought there was a bug on https://bugs.swift.org where this discussion occurred, but I cannot find it now.

AnyObject would work for me just as fine as Any, but it results in the same errors. What I am doing here is parsing binary data. I guess multiple passes of map could work.

They really are the same thing, for Elements.