You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Derived field initializers run before super(); Array#fill negative start corrupts memory; copyWithin traps when end < start #3064
Three differences from TypeScript/JavaScript semantics inside the documented subset (same results with -O0 and -O3):
Field initializers of a derived class with an explicit constructor run before super()
In a subclass with an explicit constructor, field initializers are prepended to the constructor body (compiler.ts, makeFieldInitializationInConstructor before bodyStartIndex), so they run before the super(...) call and before the base class's own field initializers. Without an explicit subclass constructor the order is right.
Array#fill(value, start) with start < -length writes before the buffer
In FILL (std/assembly/util/bytes.ts), len has type usize (unsigned), so max(len + start, 0) does not clamp a negative sum to 0 when start < -<isize>len and the loop writes before dataStart, corrupting the heap.
copyWithin(target, start, end) with end < start traps
In Array#copyWithin (std/assembly/array.ts) and TypedArray#copyWithin (std/assembly/typedarray.ts), count = min(last - from, len - to) goes negative when last < from and is cast to usize for memory.copy, trapping with memory access out of bounds instead of being a no-op.
Steps to reproduce
// 1. Derived field initializer runs before super()classA{a: i32=1;constructor(a: i32){this.a=a;}}classBextendsA{b: i32=this.a*10;constructor(){super(5);}}exportfunctionf(): i32{returnnewB().b;}// returns 0, expected 50// 2. Array#fill with start < -length corrupts heap memory before the bufferexportfunctiong(): i32{consta: i32[]=[1,2,3,4];a.fill(7,-9);// expected [7, 7, 7, 7]__collect();returna[0];// aborts: "null in ~lib/rt/itcms.ts:229:20"}// 3. copyWithin with end < start trapsexportfunctionh(): i32{consta: i32[]=[1,2,3];a.copyWithin(1,2,1);// traps: "memory access out of bounds" (expected no-op)returna.length;}
Compile with asc repro.ts -O0 (or -O3) and invoke f(), g(), and h().
Activity