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 crash with TypeError: Cannot read properties of undefined (reading 'parent') #57582

Closed
geritol opened this issue Feb 29, 2024 · 9 comments · Fixed by #57586
Closed
Assignees
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue Help Wanted You can do this

Comments

@geritol
Copy link

geritol commented Feb 29, 2024

🔎 Search Terms

Project works fine with typescript version 4.8.4, when upgrading to 4.9.4 (and any further version) type checking crashes with an internal error.

🕗 Version & Regression Information

  • This is a crash
  • This changed between versions 4.8.4 and 4.9.4
  • Error is present with typescript@next (Version 5.5.0-dev.20240229)

With the help of every-ts bisect I found the first bad commit to be:

42f9143e114c5c07f40df83ed07ffeb3cbaf2101 is the first bad commit
commit 42f9143e114c5c07f40df83ed07ffeb3cbaf2101
Author: Jack Works <jackworks@protonmail.com>
Date:   Fri Sep 30 07:13:25 2022 +0800

    feat: codefix for `for await of` (#50623)

 src/compiler/checker.ts                                | 18 +++++++++++++++++-
 src/compiler/types.ts                                  |  1 +
 src/services/codefixes/addMissingAwait.ts              |  9 +++++++++
 .../fourslash/codeFixAddMissingAwait_forAwaitOf.ts     | 17 +++++++++++++++++
 4 files changed, 44 insertions(+), 1 deletion(-)
 create mode 100644 tests/cases/fourslash/codeFixAddMissingAwait_forAwaitOf.ts

https://github.com/microsoft/TypeScript/pull/50623/files

I think error might come from errorNode being undefined here:
image

⏯ Playground Link

No response

💻 Code

No response

🙁 Actual behavior

> tsc --noEmit

[...]/node_modules/typescript/lib/tsc.js:99607
                throw e;
                ^

TypeError: Cannot read properties of undefined (reading 'parent')
    at reportTypeNotIterableError ([...]/node_modules/typescript/lib/tsc.js:71494:51)
    at getIteratedTypeOrElementType ([...]/node_modules/typescript/lib/tsc.js:71168:17)
    at checkIteratedTypeOrElementType ([...]/node_modules/typescript/lib/tsc.js:71163:20)
    at getTypeOfDestructuredArrayElement [...]/node_modules/typescript/lib/tsc.js:59574:50)
    at getAssignedTypeOfArrayLiteralElement ([...]/node_modules/typescript/lib/tsc.js:59599:20)
    at getAssignedType ([...]/node_modules/typescript/lib/tsc.js:59622:28)
    at getInitialOrAssignedType ([...]/node_modules/typescript/lib/tsc.js:60250:21)
    at getTypeAtFlowAssignment ([...]/node_modules/typescript/lib/tsc.js:60266:66)
    at getTypeAtFlowNode ([...]/node_modules/typescript/lib/tsc.js:60181:32)
    at getTypeAtFlowBranchLabel ([...]/node_modules/typescript/lib/tsc.js:60405:36)

Node.js v20.9.0

🙂 Expected behavior

no internal crash when upgrading versions

Additional information about the issue

No response

@Andarist
Copy link
Contributor

It might be quite hard to investigate this without a repro case. Would you be able to reduce your repository to one?

@geritol
Copy link
Author

geritol commented Feb 29, 2024

Don't think so, it is a huge private repository

@jakebailey
Copy link
Member

Wild guess, but I bet it has to do with:

    /**
     * When consuming an iterable type in a for..of, spread, or iterator destructuring assignment
     * we want to get the iterated type of an iterable for ES2015 or later, or the iterated type
     * of a iterable (if defined globally) or element type of an array like for ES2015 or earlier.
     */
    function getIteratedTypeOrElementType(use: IterationUse, inputType: Type, sentType: Type, errorNode: Node | undefined, checkAssignability: boolean): Type | undefined {
        const allowAsyncIterables = (use & IterationUse.AllowsAsyncIterablesFlag) !== 0;
        if (inputType === neverType) {
            reportTypeNotIterableError(errorNode!, inputType, allowAsyncIterables); // TODO: GH#18217
            return undefined;
        }

Note errorNode!; possibly a case where one needs to iterate over never?

@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Feb 29, 2024
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Feb 29, 2024
@RyanCavanaugh RyanCavanaugh added the Help Wanted You can do this label Feb 29, 2024
@geritol
Copy link
Author

geritol commented Feb 29, 2024

I have found what was causing the issue for us (valid js file with buggy implementation let someVar; [someVar] = someValue), but could not isolate a reproduction yet, will try further

@jakebailey
Copy link
Member

Yeah, this is an error path, so it's crashing instead of telling you about said bug, I would assume.

@geritol
Copy link
Author

geritol commented Feb 29, 2024

I think it is valid js (destructuring), and we had no issues reported in previous typescript versions. But if I remove the destructuring (or set the file to @ts-nocheck) crash is solved.

@jakebailey
Copy link
Member

It's valid JS, it's just code which fails to typecheck and would error but instead crashes.

@geritol
Copy link
Author

geritol commented Feb 29, 2024

managed to create a reproduction!
https://github.com/geritol/ts-bug-repro-57582

@RyanCavanaugh
Copy link
Member

Thanks!
image

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 Help Wanted You can do this
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants