Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Internal compiler crash with namespace and enum #46891

Closed
evanw opened this issue Nov 22, 2021 · 1 comment Β· Fixed by #47059
Closed

Internal compiler crash with namespace and enum #46891

evanw opened this issue Nov 22, 2021 · 1 comment Β· Fixed by #47059
Assignees
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue

Comments

@evanw
Copy link
Contributor

evanw commented Nov 22, 2021

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.

@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Nov 22, 2021
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 4.5.0 milestone Nov 22, 2021
@RyanCavanaugh
Copy link
Member

Appreciate the excellent reports as usual πŸ‘

@typescript-bot typescript-bot added the Fix Available A PR has been opened for this issue label Dec 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants