Skip to content

Internal compiler crash with namespace and enumΒ #46891

Closed
@evanw

Description

@evanw

Bug Report

πŸ”Ž Search Terms

namespace enum compiler crash computeEnumMemberValues TypeError undefined length

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

namespace x { export let y = 123 }
enum x { z = y }

πŸ™ Actual behavior

$ tsc example.ts
./node_modules/typescript/lib/tsc.js:94427
                throw e;
                ^

TypeError: Cannot read properties of undefined (reading 'length')
    at computeEnumMemberValues (./node_modules/typescript/lib/tsc.js:68888:61)
    at getEnumMemberValue (./node_modules/typescript/lib/tsc.js:70894:13)
    at evaluateEnumMember (./node_modules/typescript/lib/tsc.js:69025:36)
    at evaluate (./node_modules/typescript/lib/tsc.js:68998:61)
    at computeConstantValue (./node_modules/typescript/lib/tsc.js:68922:86)
    at computeMemberValue (./node_modules/typescript/lib/tsc.js:68907:24)
    at computeEnumMemberValues (./node_modules/typescript/lib/tsc.js:68890:33)
    at checkEnumDeclaration (./node_modules/typescript/lib/tsc.js:69051:13)
    at checkSourceElementWorker (./node_modules/typescript/lib/tsc.js:69825:28)
    at checkSourceElement (./node_modules/typescript/lib/tsc.js:69657:17)
    at Object.forEach (./node_modules/typescript/lib/tsc.js:132:30)
    at checkSourceFileWorker (./node_modules/typescript/lib/tsc.js:69985:20)
    at checkSourceFile (./node_modules/typescript/lib/tsc.js:69953:13)
    at getDiagnosticsWorker (./node_modules/typescript/lib/tsc.js:70039:17)
    at Object.getDiagnostics (./node_modules/typescript/lib/tsc.js:70028:24)
    at ./node_modules/typescript/lib/tsc.js:94448:85
    at runWithCancellationToken (./node_modules/typescript/lib/tsc.js:94420:24)
    at getBindAndCheckDiagnosticsForFileNoCache (./node_modules/typescript/lib/tsc.js:94437:20)
    at getAndCacheDiagnostics (./node_modules/typescript/lib/tsc.js:94685:26)
    at getBindAndCheckDiagnosticsForFile (./node_modules/typescript/lib/tsc.js:94434:20)
    at getSemanticDiagnosticsForFile (./node_modules/typescript/lib/tsc.js:94431:61)
    at ./node_modules/typescript/lib/tsc.js:94371:24
    at Object.flatMap (./node_modules/typescript/lib/tsc.js:428:25)
    at getDiagnosticsHelper (./node_modules/typescript/lib/tsc.js:94367:56)
    at Object.getSemanticDiagnostics (./node_modules/typescript/lib/tsc.js:94378:20)
    at emitFilesAndReportErrors (./node_modules/typescript/lib/tsc.js:99038:57)
    at Object.emitFilesAndReportErrorsAndGetExitStatus (./node_modules/typescript/lib/tsc.js:99067:18)
    at performCompilation (./node_modules/typescript/lib/tsc.js:101947:29)
    at executeCommandLineWorker (./node_modules/typescript/lib/tsc.js:101849:17)
    at Object.executeCommandLine (./node_modules/typescript/lib/tsc.js:101876:20)
    at Object.<anonymous> (./node_modules/typescript/lib/tsc.js:102170:4)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (./node_modules/typescript/bin/tsc:2:1)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
    at node:internal/main/run_main_module:17:47

πŸ™‚ Expected behavior

I expected tsc to either generate code or report an error diagnostic, but not to hard-crash like this.

For context, I'm trying to reverse-engineer what the semantics of enum/namespace interactions are to help improve esbuild's enum/namespace support. Specifically I'm investigating the feasibility of solving evanw/esbuild#1410. I hit this crash as part of that investigation and I figured it'd be useful to report it.

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFix AvailableA PR has been opened for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions