From 5edf9df5ef666cde604fdc3b19c35c2cb8ac0049 Mon Sep 17 00:00:00 2001 From: Chris Tate Date: Thu, 22 Oct 2026 21:19:05 -0500 Subject: [PATCH] Read only IR nodes as IR nodes in the code-unit locals pass --- packages/compiler/src/ir/char-unit-locals.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/compiler/src/ir/char-unit-locals.ts b/packages/compiler/src/ir/char-unit-locals.ts index 4008f4e1e..beeeffaf3 100644 --- a/packages/compiler/src/ir/char-unit-locals.ts +++ b/packages/compiler/src/ir/char-unit-locals.ts @@ -161,6 +161,10 @@ function unitLocal(local: IrLocal): IrLocal { * declaration from a one-argument charAt, a one-unit test, or a switch * over one-unit cases. */ function understoodMention(node: Record): string | null { + // count() visits every object in the body (types, locations, cases), so + // only the node kinds handled here are read as IR nodes + const kind = node.kind; + if (kind !== "varDecl" && kind !== "strEq" && kind !== "strCmp" && kind !== "switch") return null; const n = node as unknown as IrExpr | IrStmt; if (n.kind === "varDecl") return n.init && isCharAt(n.init) ? n.localId : null; if (n.kind === "strEq" || n.kind === "strCmp") return unitUse(n)?.id ?? null;