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

Crash in narrowing when using for-in #49942

Closed
DanielRosenwasser opened this issue Jul 18, 2022 · 6 comments · Fixed by #49943
Closed

Crash in narrowing when using for-in #49942

DanielRosenwasser opened this issue Jul 18, 2022 · 6 comments · Fixed by #49943
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

@DanielRosenwasser
Copy link
Member

var C = [];
for (var a in C)
    if (C.hasOwnProperty(a)) {
    }
}
TypeError: Cannot read properties of undefined (reading 'length')
    at isFunctionObjectType (c:/Users/Daniel/.vscode-insiders/extensions/ms-vscode.vscode-typescript-next-4.8.20220717/node_modules/typescript/lib/tsserver.js:70256:47)
    at getTypeFacts (c:/Users/Daniel/.vscode-insiders/extensions/ms-vscode.vscode-typescript-next-4.8.20220717/node_modules/typescript/lib/tsserver.js:70302:21)
    at isNullableType (c:/Users/Daniel/.vscode-insiders/extensions/ms-vscode.vscode-typescript-next-4.8.20220717/node_modules/typescript/lib/tsserver.js:75165:23)
    at getNonNullableTypeIfNeeded (c:/Users/Daniel/.vscode-insiders/extensions/ms-vscode.vscode-typescript-next-4.8.20220717/node_modules/typescript/lib/tsserver.js:75168:20)
    at getTypeAtFlowAssignment (c:/Users/Daniel/.vscode-insiders/extensions/ms-vscode.vscode-typescript-next-4.8.20220717/node_modules/typescript/lib/tsserver.js:71169:28)
    at getTypeAtFlowNode (c:/Users/Daniel/.vscode-insiders/extensions/ms-vscode.vscode-typescript-next-4.8.20220717/node_modules/typescript/lib/tsserver.js:71049:32)
    at getFlowTypeOfReference (c:/Users/Daniel/.vscode-insiders/extensions/ms-vscode.vscode-typescript-next-4.8.20220717/node_modules/typescript/lib/tsserver.js:71003:51)
    at checkIdentifier (c:/Users/Daniel/.vscode-insiders/extensions/ms-vscode.vscode-typescript-next-4.8.20220717/node_modules/typescript/lib/tsserver.js:72433:28)
    at checkExpressionWorker (c:/Users/Daniel/.vscode-insiders/extensions/ms-vscode.vscode-typescript-next-4.8.20220717/node_modules/typescript/lib/tsserver.js:80598:28)
    at checkExpression (c:/Users/Daniel/.vscode-insiders/extensions/ms-vscode.vscode-typescript-next-4.8.20220717/node_modules/typescript/lib/tsserver.js:80547:38)
    at checkNonNullExpression (c:/Users/Daniel/.vscode-insiders/extensions/ms-vscode.vscode-typescript-next-4.8.20220717/node_modules/typescript/lib/tsserver.js:75162:37)
    at checkPropertyAccessExpression (c:/Users/Daniel/.vscode-insiders/extensions/ms-vscode.vscode-typescript-next-4.8.20220717/node_modules/typescript/lib/tsserver.js:75207:85)
    at getSymbolOfNameOrPropertyAccessExpression (c:/Users/Daniel/.vscode-insiders/extensions/ms-vscode.vscode-typescript-next-4.8.20220717/node_modules/typescript/lib/tsserver.js:87207:25)
    at getSymbolAtLocation (c:/Users/Daniel/.vscode-insiders/extensions/ms-vscode.vscode-typescript-next-4.8.20220717/node_modules/typescript/lib/tsserver.js:87314:32)
    at Object.getSymbolAtLocation (c:/Users/Daniel/.vscode-insiders/extensions/ms-vscode.vscode-typescript-next-4.8.20220717/node_modules/typescript/lib/tsserver.js:48831:31)
    at getSymbolAtLocationForQuickInfo (c:/Users/Daniel/.vscode-insiders/extensions/ms-vscode.vscode-typescript-next-4.8.20220717/node_modules/typescript/lib/tsserver.js:167703:24)
    at Object.getQuickInfoAtPosition (c:/Users/Daniel/.vscode-insiders/extensions/ms-vscode.vscode-typescript-next-4.8.20220717/node_modules/typescript/lib/tsserver.js:166736:26)
    at IpcIOSession.Session.getQuickInfoWorker (c:/Users/Daniel/.vscode-insiders/extensions/ms-vscode.vscode-typescript-next-4.8.20220717/node_modules/typescript/lib/tsserver.js:178739:62)
    at Session.handlers.ts.Map.ts.getEntries._a.<computed> (c:/Users/Daniel/.vscode-insiders/extensions/ms-vscode.vscode-typescript-next-4.8.20220717/node_modules/typescript/lib/tsserver.js:177461:61)
    at c:/Users/Daniel/.vscode-insiders/extensions/ms-vscode.vscode-typescript-next-4.8.20220717/node_modules/typescript/lib/tsserver.js:179575:96
    at IpcIOSession.Session.executeWithRequestId (c:/Users/Daniel/.vscode-insiders/extensions/ms-vscode.vscode-typescript-next-4.8.20220717/node_modules/typescript/lib/tsserver.js:179566:28)
    at IpcIOSession.Session.executeCommand (c:/Users/Daniel/.vscode-insiders/extensions/ms-vscode.vscode-typescript-next-4.8.20220717/node_modules/typescript/lib/tsserver.js:179575:41)
    at IpcIOSession.Session.onMessage (c:/Users/Daniel/.vscode-insiders/extensions/ms-vscode.vscode-typescript-next-4.8.20220717/node_modules/typescript/lib/tsserver.js:179603:35)
    at process.<anonymous> (c:/Users/Daniel/.vscode-insiders/extensions/ms-vscode.vscode-typescript-next-4.8.20220717/node_modules/typescript/lib/tsserver.js:183769:31)
    at process.emit (node:events:390:28)
    at emit (node:internal/child_process:917:12)
    at processTicksAndRejections (node:internal/process/task_queues:84:21)

Either #49887 (@jakebailey) or #49625 (@ahejlsberg) likely caused this since it appears consistently and happened after Friday.

@DanielRosenwasser DanielRosenwasser added Bug A bug in TypeScript Crash For flagging bugs which are compiler or service crashes or unclean exits, rather than bad output labels Jul 18, 2022
@DanielRosenwasser DanielRosenwasser added this to the TypeScript 4.8.1 milestone Jul 18, 2022
@jakebailey
Copy link
Member

I can't seem to make this break; where did you hover in order to trigger the crash?

@DanielRosenwasser
Copy link
Member Author

It was on hasOwnProperty but I realized that to get it to happen with tsc, you have to be in a .js file or under --strict in a .ts file. Also, use nightly.

https://www.typescriptlang.org/play?ts=4.8.0-dev.20220718#code/G4QwTgBAwhC8EG0C6BuAUAMwPaQBSkhAgEsA7aASjQhpIwlygDoALEAZwHkB3UgBTBYADgFMwAFwCeuEBQoQA3tVoBfNCqA

@jakebailey
Copy link
Member

Thanks, I can reproduce it now.

@jakebailey
Copy link
Member

Bisected to #49330 (which isn't one of those two).

@jakebailey
Copy link
Member

jakebailey commented Jul 18, 2022

It looks like resolveStructuredTypeMembers isn't fully resolving a type. Throwing a bunch of asserts for things that should not be undefined does hit an assert (before the length check), but only fails this one test (which is good in terms of this having broken something else unknowingly).

@jakebailey
Copy link
Member

The type is an EvolvingArray, which doesn't have a case in resolveStructuredTypeMembers. (It also can't be printed, which is fun.)

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