Skip to content

array.length set to lower value should remove items properly #900

Closed
@vird

Description

@vird

array.length manipulations allowed in JS/TS so I tried this

class Struct {
  a:i32;
}
export function report(): i32 {
  let res = 0;
  let arr:Struct[] = [];
  
  for(let i=0;i<10;i++) {
    arr.push(new Struct());
  }
  arr.length = 0; // will throw here
  
  return res;
}

It produces Uncaught Error: abort: Index out of range at ~lib/rt.ts:22:27

Also setting length to higher values should allocate more memory, but fill with 0 (because on array deallocation it would try free pointer to garbage)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions