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
An enum declared in a module but referenced before its textual declaration
(valid TypeScript — enum bindings are module-scoped) is treated as an unknown
global. Member reads lower to 0 and the compiler emits:
Warning: unknown identifier '<Enum>' — assuming global; member access will
dispatch by name at runtime, bare reads lower to 0
This is a silent miscompile: the binary links but the enum value is wrong.
Minimal repro
functiontag(): First{returnFirst.B;}// used before declarationenumFirst{A="A",B="B",C="C"}console.log("fwd:",tag());
$ perry run fwd_enum.ts
Warning: unknown identifier 'First' — assuming global; member access will
dispatch by name at runtime, bare reads lower to 0
fwd: 0
Expected
fwd: B
Notes
Moving the enum declaration above its first use makes it work, confirming
it's a resolution/hoisting-order problem, not an enum-value problem.
Found in the wild at scale: zod declares ZodFirstPartyTypeKind near the end
of zod/src/v3/types.ts and references it earlier throughout the file. Compiling
zod emits ~90 of these warnings, so zod's internal type-kind dispatch (which
compares against ZodFirstPartyTypeKind.*) is silently corrupted even once it
otherwise compiles.
Summary
An
enumdeclared in a module but referenced before its textual declaration(valid TypeScript — enum bindings are module-scoped) is treated as an unknown
global. Member reads lower to
0and the compiler emits:This is a silent miscompile: the binary links but the enum value is wrong.
Minimal repro
Expected
Notes
enumdeclaration above its first use makes it work, confirmingit's a resolution/hoisting-order problem, not an enum-value problem.
zoddeclaresZodFirstPartyTypeKindnear the endof
zod/src/v3/types.tsand references it earlier throughout the file. Compilingzod emits ~90 of these warnings, so zod's internal type-kind dispatch (which
compares against
ZodFirstPartyTypeKind.*) is silently corrupted even once itotherwise compiles.
module-level binding is lost) — both look like hoisting/forward-reference
resolution gaps.
Environment
perry 0.5.1122 · macOS arm64 · native host target.