Skip to content

parity: heterogeneous element via as anys += r.x + r.y yields NaN where node string-concatenates #7776

Description

@proggeramlug

Symptom

After a different-shape element is stored into a P[] (through as any), a read loop that does s += r.x + r.y yields NaN where node string-concatenates.

Minimal reproducer

class P { x: number; y: number; constructor(x: number, y: number) { this.x = x; this.y = y; } }
class Q { x: string; y: string; constructor(x: string, y: string) { this.x = x; this.y = y; } }
function run(): number {
  const a: P[] = [];
  for (let i = 0; i < 10; i++) a.push(new P(i, i + 1));
  (a as any)[4] = new Q("z", "w");
  let s = 0;
  for (let i = 0; i < a.length; i++) { const r = a[i]; s += r.x + r.y; }
  return s;
}
console.log(run());

node 26.5.1: 16zw1113151719 (sum concatenates through the Q at index 4). Perry: NaN.

What is established

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugConfirmed defect or regression

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions