Skip to content

NL2290 does not follow a const alias of an element reference: a stale record is read after a push (native 1, Node 42) #646

Open

Description

@amritk

Summary

NL2290 refuses a read through a reference to an array element after a push may have moved the array's storage. It does not follow a second const that aliases that reference. The program below compiles. Natively it reads the record from the old storage; under Node it reads the live one.

interface P { x: i32; }
const readX = (p: P): i32 => p.x;
export const main = (): i32 => {
  const ps: P[] = [];
  for (let i: i32 = 0; i < 4; i++) { ps.push({ x: 1 }); }
  const p = ps[0];
  const q = p;                       // alias of the element reference
  for (let i: i32 = 0; i < 1000; i++) { ps.push({ x: 5 }); }
  ps[0].x = 42;
  console.log(`${readX(q)}`);        // NL2290 fires for `p` here, not for `q`
  return 0;
};
  • Native, at 1, 2 and 8 threads: prints 1.
  • Node: prints 42.

The program is single-threaded. It reproduces on main at 6729c7c and on #644's head.

Notes

Part of #575.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions