-
-
Notifications
You must be signed in to change notification settings - Fork 669
Closed
Labels
Description
So I've been thinking about the new Array<T>(10)
problematic a bit, and I figured that it might be worth to not throw on creating a holey array, but to instead throw when accessing a holey value. For instance, currently
class Foo {}
var arr = new Array<Foo>(10); // throws
but this could be modified to
class Foo {}
var arr = new Array<Foo>(10);
arr[0]; // throws
making
class Foo {}
var arr = new Array<Foo>(10);
for (let i = 0; i < 10; ++i) arr[i] = new Foo();
arr[0]; // work
at the expense of an additional runtime check whether a value is null
on element access, if the array's value type is non-nullable. Assuming that branch prediction will do fine there since actually reading a null
is unlikely and only happens in error cases. Thoughts?