Skip to content

crash in new addImplementationSuccessElaboration #41015

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

Closed
sandersn opened this issue Oct 9, 2020 · 4 comments · Fixed by #41017
Closed

crash in new addImplementationSuccessElaboration #41015

sandersn opened this issue Oct 9, 2020 · 4 comments · Fixed by #41017
Assignees
Labels
Bug A bug in TypeScript Crash For flagging bugs which are compiler or service crashes or unclean exits, rather than bad output Fix Available A PR has been opened for this issue

Comments

@sandersn
Copy link
Member

sandersn commented Oct 9, 2020

Crashes 44 packages in DT.

✔ ~/DefinitelyTyped/types/agent-base [master|✔] 
09:28 $ tsc
/home/nathansa/ts/built/local/tsc.js:105472
                throw e;
                ^

TypeError: Cannot read property 'length' of undefined
    at getSignatureFromDeclaration (/home/nathansa/ts/built/local/tsc.js:53357:89)
    at addImplementationSuccessElaboration (/home/nathansa/ts/built/local/tsc.js:67988:37)
    at resolveCall (/home/nathansa/ts/built/local/tsc.js:67955:25)
    at resolveCallExpression (/home/nathansa/ts/built/local/tsc.js:68284:20)
    at resolveSignature (/home/nathansa/ts/built/local/tsc.js:68657:28)
    at getResolvedSignature (/home/nathansa/ts/built/local/tsc.js:68688:26)
    at checkCallExpression (/home/nathansa/ts/built/local/tsc.js:68814:29)
    at checkExpressionWorker (/home/nathansa/ts/built/local/tsc.js:71378:28)
    at checkExpression (/home/nathansa/ts/built/local/tsc.js:71287:38)
    at checkExpressionStatement (/home/nathansa/ts/built/local/tsc.js:73819:13)

Added in #41001

@sandersn sandersn added this to the TypeScript 4.1.1 milestone Oct 9, 2020
@sandersn sandersn added Bug A bug in TypeScript Crash For flagging bugs which are compiler or service crashes or unclean exits, rather than bad output labels Oct 9, 2020
@sandersn
Copy link
Member Author

sandersn commented Oct 9, 2020

calling getSignatureFromDeclaration on a ModuleDeclaration, which has no parameters, so declaration.parameters.length crashes.

@sandersn
Copy link
Member Author

sandersn commented Oct 9, 2020

Overloaded ambient function merged with namespace, such that the function implementation is not the last declaration. An easy fix is to skip such merges, although it's probably possible to use a different method to find the implementation declaration.

This crash might only apply in d.ts files, where there IS no implementation.

declare namespace Agent {
  interface Agent { ... }
}
declare function Agent(opts?): Agent.Agent;
declare function Agent(callback, opts?): Agent.Agent;
export = Agent;

@weswigham
Copy link
Member

The crash is just because of an unchecked cast - turns out having a .body member isn't enough to guarantee the declaration is function-like, since namespaces also have a .body 😛 - PR is up: #41017

@typescript-bot typescript-bot added the Fix Available A PR has been opened for this issue label Oct 9, 2020
@minestarks
Copy link
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Crash For flagging bugs which are compiler or service crashes or unclean exits, rather than bad output 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