@@ -4,7 +4,7 @@ import { BLOCK_MAXSIZE } from "./rt/common";
4
4
import { COMPARATOR , SORT } from "./util/sort" ;
5
5
import { joinBooleanArray , joinIntegerArray , joinFloatArray , joinStringArray , joinReferenceArray } from "./util/string" ;
6
6
import { idof , isArray as builtin_isArray } from "./builtins" ;
7
- import { E_INDEXOUTOFRANGE , E_INVALIDLENGTH , E_EMPTYARRAY , E_HOLEYARRAY } from "./util/error" ;
7
+ import { E_INDEXOUTOFRANGE , E_INVALIDLENGTH , E_ILLEGALGENTYPE , E_EMPTYARRAY , E_HOLEYARRAY } from "./util/error" ;
8
8
9
9
/** Ensures that the given array has _at least_ the specified backing size. */
10
10
function ensureSize ( array : usize , minSize : usize , alignLog2 : u32 ) : void {
@@ -367,7 +367,12 @@ export class Array<T> {
367
367
base + sizeof < T > ( ) ,
368
368
< usize > lastIndex << alignof < T > ( )
369
369
) ;
370
- store < T > ( base + ( < usize > lastIndex << alignof < T > ( ) ) , changetype < T > ( 0 ) ) ;
370
+ if ( isReference < T > ( ) ) {
371
+ store < usize > ( base + ( < usize > lastIndex << alignof < T > ( ) ) , 0 ) ;
372
+ } else {
373
+ // @ts -ignore
374
+ store < T > ( base + ( < usize > lastIndex << alignof < T > ( ) ) , < T > 0 ) ;
375
+ }
371
376
this . length_ = lastIndex ;
372
377
return element ; // no need to retain -> is moved
373
378
}
@@ -496,7 +501,7 @@ export class Array<T> {
496
501
497
502
flat ( ) : T {
498
503
if ( ! isArray < T > ( ) ) {
499
- ERROR ( "Cannot call flat() on Array<T> where T is not an Array." ) ;
504
+ throw new TypeError ( E_ILLEGALGENTYPE ) ;
500
505
}
501
506
// Get the length and data start values
502
507
var length = this . length_ ;
0 commit comments