Closed
Description
Hi,
I am currently writing a chess engine in AssemblyScript and for optimization purposes I wanted to replace some Arrays with TypedArrays.
Unfortunately, after the change some of my unit tests started to fail with error "An orphaned decrement has occurred...".
After some debugging, I noticed that the error seems to occur when sorting the array.
Here is a minimal code snippet to reproduce the error:
function reproduceBug(): i32 {
let moves = new Int32Array(1);
moves[0] = 1;
moves.sort();
return moves[0];
}
describe("Bug?", () => {
it("causes error 'An orphaned decrement has occured'", () => {
const result = reproduceBug();
expect(result).toBe(1);
});
})
Here is the error message when running the test with as-pect:
[Error]: Orphaned Decrement Error: An orphaned decrement has occurred at block: 4784
[Stack]: at ~lib/rt/pure/decrement (wasm-function[54]:23)
at ~lib/rt/pure/__release (wasm-function[55]:13)
at assembly/__tests__/util.spec/reproduceBug (wasm-function[127]:41)
at start:assembly/__tests__/util.spec~anonymous|5~anonymous|0 (wasm-function[129]:3)
at node_modules/@as-pect/assembly/assembly/internal/call/__call (wasm-function[133]:7)
AssemblyScript version: 0.8.1