Skip to content

Crash involving union of function types #31485

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
tomblind opened this issue May 20, 2019 · 1 comment · Fixed by #31560
Closed

Crash involving union of function types #31485

tomblind opened this issue May 20, 2019 · 1 comment · Fixed by #31560
Assignees
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@tomblind
Copy link

TypeScript Version: 3.5.0-dev.20190518

Search Terms:
Cannot read property 'flags' of undefined
createSymbolWithType

Code

interface A {
    (this: void, a: string, b: number, c?: string): void;
    (this: void, b: number, c?: string): void;
}
interface B {
    (i: number): number;
}
declare const fn: A | B;
fn(0);

Expected behavior:
Should not crash.

Actual behavior:
tsc crashes with the following output:

node_modules\typescript\lib\tsc.js:72973
                throw e;
                ^

TypeError: Cannot read property 'flags' of undefined
    at createSymbolWithType (node_modules\typescript\lib\tsc.js:36787:46)
    at getUnionSignatures (node_modules\typescript\lib\tsc.js:30929:53)
    at resolveUnionTypeMembers (node_modules\typescript\lib\tsc.js:31021:34)
    at resolveStructuredTypeMembers (node_modules\typescript\lib\tsc.js:31330:21)
    at getSignaturesOfStructuredType (node_modules\typescript\lib\tsc.js:31782:32)
    at getSignaturesOfType (node_modules\typescript\lib\tsc.js:31788:20)
    at resolveCallExpression (node_modules\typescript\lib\tsc.js:42223:34)
    at resolveSignature (node_modules\typescript\lib\tsc.js:42494:28)
    at getResolvedSignature (node_modules\typescript\lib\tsc.js:42514:26)
    at checkCallExpression (node_modules\typescript\lib\tsc.js:42585:29)

Playground Link:

Related Issues:
#29884 may be related, as there's an example with a similar callstack, but it's closed as fixed already.

@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label May 21, 2019
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 3.5.0 milestone May 21, 2019
@andrewbranch
Copy link
Member

andrewbranch commented May 22, 2019

Hah, that second stack frame:

// TODO: GH#18217 We tested that *some* has thisParameter and now act as if *all* do
const thisType = getUnionType(map(unionSignatures, sig => sig.thisParameter ? getTypeOfSymbol(sig.thisParameter) : anyType), UnionReduction.Subtype);
thisParameter = createSymbolWithType(signature.thisParameter!, thisType);

🙃

(#18217)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue
Projects
None yet
3 participants