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

Compiler crash on exports.fn pattern #42350

Closed
mihailik opened this issue Jan 14, 2021 · 4 comments · Fixed by #42766
Closed

Compiler crash on exports.fn pattern #42350

mihailik opened this issue Jan 14, 2021 · 4 comments · Fixed by #42766
Assignees
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue

Comments

@mihailik
Copy link
Contributor

mihailik commented Jan 14, 2021

Bug Report

🔎 Search Terms

🕗 Version & Regression Information

  • This is a crash
  • This changed between versions 4.0.5 and 4.1.3

⏯ Playground Link

2-line example

💻 Code

exports.fn1();
exports.fn2 = Math.min;

🙁 Actual behavior

Crashing:

TypeError: Cannot read property 'length' of undefined
    at getPropertyOfType (C:\Users\mihai\danfo\node_modules\typescript\lib\tsc.js:44083:45)
    at getTypeOfDottedName (C:\Users\mihai\danfo\node_modules\typescript\lib\tsc.js:52423:44)
    at getEffectsSignature (C:\Users\mihai\danfo\node_modules\typescript\lib\tsc.js:52436:32)
    at getTypeAtFlowCall (C:\Users\mihai\danfo\node_modules\typescript\lib\tsc.js:52755:33)
    at getTypeAtFlowNode (C:\Users\mihai\danfo\node_modules\typescript\lib\tsc.js:52636:32)
    at getFlowTypeOfReference (C:\Users\mihai\danfo\node_modules\typescript\lib\tsc.js:52593:51)      
    at checkIdentifier (C:\Users\mihai\danfo\node_modules\typescript\lib\tsc.js:53580:28)
    at checkExpressionWorker (C:\Users\mihai\danfo\node_modules\typescript\lib\tsc.js:59973:28)       
    at checkExpression (C:\Users\mihai\danfo\node_modules\typescript\lib\tsc.js:59928:38)
    at checkNonNullExpression (C:\Users\mihai\danfo\node_modules\typescript\lib\tsc.js:55612:37)      

This is running tsc.js with: node --inspect-brk node_modules\typescript\lib\tsc.js repor.js --out repor.out.js --allowJs and some state in context:

image

🙂 Expected behavior

Transpile, don't crash. Can produce errors/warnings, but not crash.

Background

This happened when I tried to run TypeScript over the latest CodeMirror, and stumbled upon the file runmode.node.js (see on unpkg). Then, simplified to the minimal reproduction case.

As you can see from the caught error above, resolved.callSignatures is undefined and that causes throw here.

I assume this happens because exports isn't treated as a normal global variable even in a variable position. But in variable position it should be treated as a variable.

Note: can't simplify any more, both lines are necessary. Which means it's not just bad handling of exports, but something more conspiratorial.

@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Jan 14, 2021
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 4.3.0 milestone Jan 14, 2021
@mihailik
Copy link
Contributor Author

Sorry, I think it really should be more urgent than 4.3.0.

It's not an obscure bug, TypeScript currently crashes on CodeMirror -- arguably the most basic core library on the web, everyone on here touches it daily in Sources and Console tab of DevTools.

@RyanCavanaugh
Copy link
Member

Is the regression information accurate? 4.1 came out two months ago and this is the first we've heard of it, which would indicate this isn't as critical as you're describing.

eventualbuddha added a commit to votingworks/vxsuite that referenced this issue Jan 19, 2021
This required pinning typescript to v4.0.5 due to microsoft/TypeScript#42350. I don't yet understand why this bug manifested with pnpm and not with yarn, but it may get fixed in TS 4.3.0 or earlier.
eventualbuddha added a commit to votingworks/vxsuite that referenced this issue Jan 19, 2021
This required pinning typescript to v4.0.5 due to microsoft/TypeScript#42350. I don't yet understand why this bug manifested with pnpm and not with yarn, but it may get fixed in TS 4.3.0 or earlier.
eventualbuddha added a commit to votingworks/vxsuite that referenced this issue Jan 19, 2021
This required pinning typescript to v4.0.5 due to microsoft/TypeScript#42350. I don't yet understand why this bug manifested with pnpm and not with yarn, but it may get fixed in TS 4.3.0 or earlier.
eventualbuddha added a commit to votingworks/vxsuite that referenced this issue Jan 19, 2021
This required pinning typescript to v4.0.5 due to microsoft/TypeScript#42350. I don't yet understand why this bug manifested with pnpm and not with yarn, but it may get fixed in TS 4.3.0 or earlier.
@eventualbuddha
Copy link

I don't have much to contribute in terms of helping identify why this happens, but I ran into it while trying to move from yarn to pnpm: votingworks/vxsuite#146. Downgrading to TS 4.0.5 fixed it.

elibarzilay added a commit to elibarzilay/TypeScript that referenced this issue Feb 11, 2021
…tPropertyOfType`

e350c35 (microsoft#40228) introduced a subtle bug: it switched the flags to an
alias, dropping `SymbolFlags.Property` --- and that makes
`symbolIsValue()` get to the `resolveAlias(symbol)` call, which leads to
`getPropertyOfType()` with`resolved.callSignatures`+`constructSignatures`
being `undefined`.  So initialize them in `setStructuredTypeMembers`
before calling `getNamedMembers()`.

Fixes microsoft#42350
@typescript-bot typescript-bot added the Fix Available A PR has been opened for this issue label Feb 11, 2021
elibarzilay added a commit to elibarzilay/TypeScript that referenced this issue Feb 11, 2021
…tPropertyOfType`

e350c35 (microsoft#40228) introduced a subtle bug: it switched the flags to an
alias, dropping `SymbolFlags.Property` --- and that makes
`symbolIsValue()` get to the `resolveAlias(symbol)` call, which leads to
`getPropertyOfType()` with`resolved.callSignatures`+`constructSignatures`
being `undefined`.  So initialize them in `setStructuredTypeMembers`
before calling `getNamedMembers()`.

Fixes microsoft#42350
elibarzilay added a commit that referenced this issue Feb 11, 2021
…tPropertyOfType`

e350c35 (#40228) introduced a subtle bug: it switched the flags to an
alias, dropping `SymbolFlags.Property` --- and that makes
`symbolIsValue()` get to the `resolveAlias(symbol)` call, which leads to
`getPropertyOfType()` with`resolved.callSignatures`+`constructSignatures`
being `undefined`.  So initialize them in `setStructuredTypeMembers`
before calling `getNamedMembers()`.

Fixes #42350
@minestarks
Copy link
Member

typescript-bot pushed a commit to typescript-bot/TypeScript that referenced this issue Feb 25, 2021
Component commits:
ed26816 Avoid getting undefined `callSignatures`/`constructSignatures` in `getPropertyOfType`
e350c35 (microsoft#40228) introduced a subtle bug: it switched the flags to an
alias, dropping `SymbolFlags.Property` --- and that makes
`symbolIsValue()` get to the `resolveAlias(symbol)` call, which leads to
`getPropertyOfType()` with`resolved.callSignatures`+`constructSignatures`
being `undefined`.  So initialize them in `setStructuredTypeMembers`
before calling `getNamedMembers()`.

Fixes microsoft#42350
RyanCavanaugh pushed a commit that referenced this issue Feb 25, 2021
Component commits:
ed26816 Avoid getting undefined `callSignatures`/`constructSignatures` in `getPropertyOfType`
e350c35 (#40228) introduced a subtle bug: it switched the flags to an
alias, dropping `SymbolFlags.Property` --- and that makes
`symbolIsValue()` get to the `resolveAlias(symbol)` call, which leads to
`getPropertyOfType()` with`resolved.callSignatures`+`constructSignatures`
being `undefined`.  So initialize them in `setStructuredTypeMembers`
before calling `getNamedMembers()`.

Fixes #42350

Co-authored-by: Eli Barzilay <eli@barzilay.org>
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
6 participants